On May 20, 7:25 am, Jonathan_C <[EMAIL PROTECTED]> wrote:
> I'm writing some code to subset a table based on the contents of
> particular columns. My event handler starts off like this:
>
> subsetChange: function(e) {
> var subset = $F('subsetSelector');
> var rows = $$('.content-row');
rows isn'ta good variable name as table and table section elements
have a rows collection, so may be confusing.
> rows.each(function(row) {
> var value = row.down('.Platform_Category').childNodes[0].data;
> switch (subset) {
>
> ... show/hide rows based on whether the value matches the user
> selected subset ...
>
> My question is whether there is a more Prototype-ish way to get the
> values from my table cells instead of using ".childNodes[0].data".
Why not use either DOM 3 textContent or IE innerText? e.g.
function getText (el) {
if (typeof el.textContent == 'string') return el.textContent;
if (typeof el.innerText == 'string') return el.innerText;
}
Or if you want to be "Prototypeis":
Element.addMethods({
getText: function(element) {
element = $(element);
if (typeof element.textContent == 'string') {
return element.textContent;
}
if (typeof element.innerText == 'string') {
return element.innerText;
}
}
});
Table rows have a cells collection that contains all the cells in the
row, so if you want the content of the first cell:
var value = rows[i].cells[0].getText();
--
Rob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to rubyonrails-spinoffs@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---