Alex Rivera | Logout

Use .get(0) or .html() to return HTML with jQuery

Asked 2011-11-17T00:17:55.067
8

So as far as I can tell, if I have

<div id="thing">OMG there's awesome stuff in here</div>

and need to plant that html somewhere else, I have the option of using:
$('#thing').html(); or $('#thing').get(0);

Is there a greater internet standard in using one or the other? They do the exact same thing, right?

Thanks for the help!

Edit
Report

1 Answer

1

No, they do not do the exact same thing.

.html() returns HTML string representing the DOM structure inside the element contained within the jQuery collection object: "OMG there's awesome stuff in here".

.get(0) returns the first DOM element object from the collection, in this case a DOM node of tag-type DIV with ID "thing" and child text-node with value "OMG there's awesome stuff in here"

answered 2011-11-17T00:20:58.860

Your Answer