javascript - What is the fastest way to see if a node has a child with a specific tag? -
i want check if node has tag in or 1 of it's children in javascript.
<html> <body> <p> <h3><a> link lead nowhere!</a> </h3> </p> </body> </html>
for example, in above code, if given node responsible p tag, , want check if has link in it, fastest way check (without having actual node link)?
if given node's name "node", faster do:
function nodecontainstag(node) { return node.tagname == "a" || node.getelementsbytagname("a").length > 0 ; }
or
function nodecontainstag(node) { return node.outerhtml.indexof("<a") > 0; }
is second function guaranteed work (i.e. need check case sensitivity ("<a"
) , spacing (ex: "< a"
)?
this function works faster
function nodecontainstag(node) { return node.tagname == "a" || node.getelementsbytagname("a").length > 0 ; }
also queryselector works slower these.
Comments
Post a Comment