Reputation: 12148
I have a group of objects on my page. I want to get the first one, so I do this:
var tmpLi = li.first();
console.dir(tmpLi);
This works fine; it returns this in firebug:
I need to return the value of the outerHTML element, but can't seem to figure out how to get it. I've tried:
var tmpLi = li.first().data("outerHTML");
and
var tmpLi = li.first().attr("outerHTML");
both of which return "undefined". Help?
Upvotes: 1
Views: 112
Reputation: 179264
You either need to use the prop
method, which gets the underlying object's property value:
li.first().prop('outerHTML');
...or unwrap the DOM object from the jQuery selection:
li[0].outerHTML
Upvotes: 1
Reputation: 26320
It returns an object, so you have to access it like the following.
li.first()[0].outerHTML
Upvotes: 1