I have an input element like: <input class="input-m" name="formelement[]" type="text">
I want to clone it and store cloned html to a variable:
var txt=jQuery("input[name="+n+"[]]:first").clone().html();
this returns an empty string.
How can I get the html content from .clone()
?
Try this
var txt=jQuery("input[name="+n+"[]]:first").clone().wrap("<div />").parent().html();
I think you want the outer HTML instead of innerHTML:
var text = $('<div>').append(jQuery("input[name="+n+"[]]:first").clone()).html();
.html()
returns the html inside the element. I am guessing you have something like <input name="..."/>
which has no inner html.
You should probably rely on something like outerHtml plugin.