I have the following code to get an element by it's attribute:
document.getElementsByAttribute("xlink:href",id);
I get this error:
Uncaught TypeError: document.getElementsByAttribute is not a function
I don't understand what's going wrong, is it not a standard chrome function?
The getAttribute() method of the Element interface returns the value of a specified attribute on the element. If the given attribute does not exist, the value returned will either be null or "" (the empty string); see Non-existing attributes for details.
HTML DOM getAttribute() method is used to get the value of the attribute of the element. By specifying the name of the attribute, it can get the value of that element. To get the values from non-standard attributes, we can use the getAttribute() method.
How it works: First, select the link element with the id js using the querySelector() method. Second, get the target attribute of the link by calling the getAttribute() of the selected link element. Third, show the value of the target on the Console window.
From documentation:
Note that this method is only available on XUL elements; it is not part of the W3C DOM.
Use this:
document.querySelectorAll("[xlink|href='"+id+"']");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With