0

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

1
  • 1
    Void elements don't have closing tag. Commented Mar 4, 2014 at 10:09

2 Answers 2

4

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

$(".me").after($(".me").clone());
Sign up to request clarification or add additional context in comments.

3 Comments

Argh! that's why! innerHtml is the key word, it works! thanks! I'll come back in 12 mins and accept the answer
you can't accept answer within 15min, at least i can't
@C-link ignore them every forum will have its own share of crazys
0

Just call the clone tag

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

2 Comments

don't copy paste answers
Sorry, I didn't refreshed my page and somebody gave you an answer already :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.