Discussion:
Looking a helper function which searches an element with a specified attribute name and value
meryl
2010-04-27 05:48:25 UTC
Permalink
Hi,

Can you please tell me if there is any helper function which searches
within a nsDocument and return an element with a specified attribute
name an value.

It is kind GetElementById() but not looking for 'id' attribute only.

Thank you.
Boris Zbarsky
2010-04-27 11:09:19 UTC
Permalink
Post by meryl
Hi,
Can you please tell me if there is any helper function which searches
within a nsDocument and return an element with a specified attribute
name an value.
It is kind GetElementById() but not looking for 'id' attribute only.
XUL documents have getElementsByAttribute.

-Boris
meryl
2010-04-28 06:47:39 UTC
Permalink
Post by Boris Zbarsky
Post by meryl
Hi,
Can you please tell me if there is any helper function which searches
within a nsDocument and return an element with a specified attribute
name an value.
It is kind GetElementById() but not looking for 'id' attribute only.
XUL documents have getElementsByAttribute.
-Boris
I have a pointer of nsIDOMDocument (that is the DOM of a rendered
page), when I try to get the nsIDOMXULDocument so that I can use that
getElementsByAttribute() method, it returns NULL. How can I use that
getElementsByAttribute() method if i have a pointer of nsIDOMDocument?

nsCOMPtr<nsIDOMXULDocument> xulDoc = do_QueryInterface(domDoc);

Thank you.
Boris Zbarsky
2010-04-28 07:57:14 UTC
Permalink
Post by meryl
I have a pointer of nsIDOMDocument (that is the DOM of a rendered
page), when I try to get the nsIDOMXULDocument so that I can use that
getElementsByAttribute() method, it returns NULL.
Then your document is not a XUL document and you can't use
getElementsByAttribute.

Come to think of which... is there a reason querySelector or
querySelectorAll can't do what you want?

-Boris

Loading...