1.throws the above errot: object #<htmlDivElement> has no method 'attr' function changeId(){
var l=$("._question").length; var question = $("._question");
for(var i=0;i<l;i++){
alert(question[i]attr("id"));
}
}
2..attr()
only exists on a jquery object, not on a DOM object. schemes[i]
gets a DOM object. And, never use for x in obj
to iterate an array. It iterates all properties, not just array elements. Use .eq(i)
to get a jquery object.
3.
If you use for-loop
to
iterate jQuery set, you should get the elements with eq()
method,
but not using square bracket notation (i.e. []
).
The code like $("._question")[i]
will
pick up DOM elements, but not jQuery
objects.