Issue
I have 16 divs with the class "box" and each "box" has a different name.
The first "box" has name="box1";
the second "box" has name="box2";
the third "box" has name="box3";
and so on.....
I want to select these individual names, so I attempted to use the following code:
for (var i = 0; i < $(".box").length; i++) {
console.log($(".box")[i].attr("name"));
}
But my console shows that "$(...)[i].attr is not a function".
When I tried this:
for (var i = 0; i < $(".box").length; i++) {
console.log($(".box").attr("name"));
}
I get back 16 lines of "box1", which is only the name for the first "box" div.
What I want instead is "box1, box2, box3, box4, box5..."
What can I do?
Solution
Using jQuery:
$( ".box" ).each(function( index ) {
console.log($(this).attr("name") );
});
Answered By - domenikk
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.