Frage

I am new to this...

I am looking to search a single column in a single table (No ID attached) on one page and I'm stumped. Everything I've found has to do with redrawing the table or getting the value. I'm not looking to do that or to replace any value. Basically I want to search a table for a string "Is Closed". If it is found, then I will show a button using $('button').show() or $('button').hide()

I am pretty sure I would have to do a $$(".table name") to find the table, correct? How do I go about searching the colum for "Is Closed" string

Looking to use only JS or prototype, no JQuery

War es hilfreich?

Lösung

You need to be able to identify the table somehow, ID or class will work, or if you are absolutely sure its going to be the only table on the page that will work too.

Table with an id

var results = $('tableid').select('td').filter(function(cell){
    return cell.innerHTML.match(/Is Closed/);
});

Table with a class

var results = $$('.tableclass').first().select('td').filter(function(cell){
    return cell.innerHTML.match(/Is Closed/);
});

Or only table on the page (I don't recommend you use this method)

var results = $$('table').first().select('td').filter(function(cell){
    return cell.innerHTML.match(/Is Closed/);
});

results will be an array of table cells that contain the words 'Is Closed'

Andere Tipps

searchstring = document.getElementsById('searchstring');
for (i=0, i<searchstring.length; i++) { 
    if (searchstring.rows[i].cells[0] == givenValue) { 
        alert('found string'); 
    }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top