I am trying to store an array of objects in an array by going through each paragraph element in a div container with the .get() method. I try to access the attribute with .attr() but it doesn’t seem to work. How would I modify this code in order to be able to access the ‘id’ attribute of each message?
var messages = $("#message_container p").get();
var idstest = [];
for (int i = 0; i < messages.length; i++){
idstest.push(messages[i].attr("id"));
}
I think it has to do with some fundamental incompatibility with .get() and .attr(). When I ‘alert’ the objects provided by .get() I get [object HTML---]. I’m assuming that is not the form necessary in order to use .attr?
getwill give you the DOM element. These are NOT jquery objects so you can’t useattron them. There’s no reason to usegetat all here.http://jsfiddle.net/ujdeH/
EDIT: You also can’t use
int.If for some reason you did want to use
getto get the raw DOM elements, you would then just use.id:http://jsfiddle.net/ujdeH/1/