Alex Pliutau
Alex Pliutau

Reputation: 21957

jQuery get current element (x)html

I have the next input element:

<input type="text" name="username" id="username" value="user name" 
    helper="formText" defvalue="user name" class="filling" />

How can I get this html by id "username" with help of jQuery?

I try to make it with get(), html(). But I want to get html of current element.

Thank you in advance.

Sorry for my english.

Upvotes: 2

Views: 5006

Answers (1)

Nick Craver
Nick Craver

Reputation: 630389

You can't get the exact HTML (as different browsers handle this differently), but closest you can get is appending a cloned version to a temporary element and taking the .innerHTML of that, like this:

var html = $("<div/>").append($("#username").clone()).html();

Upvotes: 6

Related Questions