If someone needs to do this without jQuery , just with plain Javascript, and for Google Chrome (webkit) , this is the only way to find it working after a lot of research and testing.
parentNode.getElementsByTagNameNS("*", "name");
This will work to get the following node: <prefix:name> . As you can see, the prefix or namespace is omitted, and it will match elements with different namespaces if the name tag is name . But hopefully this will not be a problem for you.
None of this worked for me (I am developing a Google Chrome extension):
getElementsByTagNameNS("prefix", "name")
getElementsByTagName("prefix:name")
getElementsByTagName("prefix\\:name")
getElementsByTagName("name")
Edit : after some sleep, I found a workaround :). This function returns the first node corresponding to the full nodeName , for example, <prefix:name> :
// Helper function for nodes names that include a prefix and a colon, such as "<yt:rating>" function getElementByNodeName(parentNode, nodeName) { var colonIndex = nodeName.indexOf(":"); var tag = nodeName.substr(colonIndex + 1); var nodes = parentNode.getElementsByTagNameNS("*", tag); for (var i = 0; i < nodes.length; i++) { if (nodes[i].nodeName == nodeName) return nodes[i] } return undefined; }
It can be easily changed if you need to return all the relevant elements. Hope this helps!
cprcrack Jul 25 2018-11-11T00: 00Z
source share