Add list elements in DOM to array in JS
I have a un-ordered list containing links with the same class and a unique ID, I need to add all those ID's to an array in javascript with.
<ul>
<li><a class="item" id="10" href="#"></a></li>
<li><a class="item" id="11" href="#"></a></li>
<li><a class="item" id="12" href="#"></a></li>开发者_高级运维
<ul>
How could I do this?
var ids = document.getElements("ul li a.item").get("id");
console.log(ids); // ["10", "11", "12"]
an easier (more mootools-like) way to do what @Dimitar did:
var ids = $$('.item').get('id');
Good Luck
精彩评论