I need a function to get the value of the name attribute of each element with class="class". I was wondering what is the best way to do this, performance-wise.
Currently I'm using jQuery and doing it like this:
$("#Button").click(function() {
var myElements = $(".class");
for (var i=0;i<myElements.length;i++) {
alert(myElements.eq(i).attr("name"));
}
});
Alert is just to show what it does, of course. For the following HTML:
<input type="checkbox" class="class" name="1">
<input type="checkbox" class="nope" name="2">
<input type="checkbox" class="class" name="3">
It would issue:
alert("1")
alert("3")
I was wondering if using pure Javascript would be faster, or if there is any other (better) way of doing it. I apologize if this question is not on this website's scope, please move it to Stackoverflow if that's the case.