javascriptgoogle-chrome

getElementsByAttribute() is not a function


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?


Solution

  • 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+"']");