Andrew wrote:
> I'm fairly new to Prototype and I was wondering if anyone can help me
> out here.
>
> i need to search the document for elements with a specific innerHTML.
> I have the innerHTML string already, but i dont know how to find the
> elements with that property.
>
> thanks,
> andrew
Maybe the fastest would be this:
var findHtml = 'Find Me!';
var elements = document.getElementsByTagName('*');
var found = [];
for (var i = 0, len = elements.length; i < len; i++) {
if (elements[i].innerHTML == findHtml) {
found.push(elements[i]);
}
}
You could use $$() but in IE it would extend each element and be slow.
You could use $A() but it also may be slow.
Preferably you'd want to specify a tag name instead of '*'.
- Ken Snyder
// options that use Prototype
// $$()
$$('*').findAll(function(element) {
return element.innerHTML == findHtml;
});
// $A()
$A(document.getElementsByTagName('*')).findAll(function(element) {
return element.innerHTML == findHtml;
});
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---