Say I have the following in my HTML file
<div class="foo"> item1 </div>
<div class="foo"> item2 </div>
<div class="foo"> item3 </div>
I can easily get all these divs using the following JavaScript code:
document.getElementsByClassName("foo")
Here, foo is defined somewhere in a CSS file as follows:
.foo { /* Some style */ }
Now, the question is, sometimes one would define foo as a custom HTML tag as follows
foo { /* Some style */ }
to allow for more succinct HTML:
<foo> item1 </foo>
<foo> item2 </foo>
<foo> item3 </foo>
But then the JavaScript line above does not work anymore. How should one get all the foo nodes in this case?
document.getElementsByTagName('foo')does not work for you?