Reputation: 2726
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 div
s 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?
Upvotes: 3
Views: 168
Reputation: 631
use same class like this
<foo class="foo"> item1 </foo>
<foo class="foo"> item2 </foo>
<foo class="foo"> item3 </foo>
or use
document.getElementsByTagName("foo")
Upvotes: 1