ah-shiang han
ah-shiang han

Reputation: 330

jQuery html() cannot get <input>?

So I've came across with this weird behavior, not quite sure what I'm doing wrong Tried searching but no luck...

So basically, I had a simple input, can be anything

<input class="me" type="text" name="me" value="3"></input>

Then I want to copy itself

$(".me").after($(".me").html());

But somehow it's not working, any suggestions? Please note that I don't need .val() and create a new one, I want to copy the whole input tag as there'll be input, textarea, select, etc... Thanks in advance

http://jsfiddle.net/GEWQ9/1/

P.S. if I choose span instead of input, it works fine, which is weird

Upvotes: 0

Views: 58

Answers (2)

Sorin
Sorin

Reputation: 757

Just call the clone tag

$(".me").after($(".me").clone());

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388446

because .html() get innerHTML, and input element does not have any inner html, you need to clone the input element

$(".me").after($(".me").clone());

Upvotes: 4

Related Questions