{"id":55,"date":"2004-06-04T16:38:07","date_gmt":"2004-06-04T21:38:07","guid":{"rendered":"http:\/\/sovogo.com\/2004\/06\/04\/getelementsbyclass-what-about-dom-xpath\/"},"modified":"2004-06-04T16:38:07","modified_gmt":"2004-06-04T21:38:07","slug":"getelementsbyclass-what-about-dom-xpath","status":"publish","type":"post","link":"https:\/\/dylanschiemann.com\/?p=55","title":{"rendered":"getElementsByClass: what about dom xpath?"},"content":{"rendered":"<p>Daniel Glazman has added an entry about <a href=\"http:\/\/www.glazman.org\/weblog\/newarchive\/2003_06_01_glazblogarc.html#s95287073\">three ways to emulate getElementsByClass<\/a>.  Of course, there&#8217;s another method if your document is xhtml: use xpath like this&#8230;\n<\/p>\n<p>\nfunction getElementByClassName(needle) {<br \/>\nvar xpathResult = document.evaluate(&#8216;\/\/*[@class = &#8220;&#8216;needle'&#8221;]&#8217;, document, null, 0, null);<br \/>\nvar outArray = new Array();<br \/>\nvar item;<br \/>\nwhile (item = xpathResult.iterateNext()) outArray[outArray.length] = item;<br \/>\nreturn outArray;<br \/>\n}<\/p>\n<p>\nCode updated to address two minor issues brought to my attention by Biju.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Daniel Glazman has added an entry about three ways to emulate getElementsByClass. Of course, there&#8217;s another method if your document is xhtml: use xpath like this&#8230; function getElementByClassName(needle) { var xpathResult = document.evaluate(&#8216;\/\/*[@class = &#8220;&#8216;needle&#8217;&#8221;]&#8217;, document, null, 0, null); var outArray = new Array(); var item; while (item = xpathResult.iterateNext()) outArray[outArray.length] = item; return outArray; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6,1],"tags":[],"_links":{"self":[{"href":"https:\/\/dylanschiemann.com\/index.php?rest_route=\/wp\/v2\/posts\/55"}],"collection":[{"href":"https:\/\/dylanschiemann.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dylanschiemann.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dylanschiemann.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dylanschiemann.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=55"}],"version-history":[{"count":0,"href":"https:\/\/dylanschiemann.com\/index.php?rest_route=\/wp\/v2\/posts\/55\/revisions"}],"wp:attachment":[{"href":"https:\/\/dylanschiemann.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=55"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dylanschiemann.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=55"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dylanschiemann.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=55"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}