Reputation:
<ul>
<li year='2014'> </li>
<li year='2014'> </li>
<li year='2014'> </li>
<li year='2015'> </li>
</ul>
Using Javascript how can I select those li
item whose year attribute is set to 2014. I tried the following, but it did not work:
document.getElementsByTagName("li[value=='2015']);
Upvotes: 0
Views: 97
Reputation: 66663
You can use document.querySelectorAll()
for this:
In this case, the usage should be document.querySelectorAll('li[year="2014"]')
Demo: http://jsfiddle.net/njvwxsxd/
Docs: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll
Upvotes: 3