Why doesn't this jquery line ...">

Why not work on a cloned object?

I can not make it work.

<div id=​​​​​​​​​​​​"xrod"><input class="yrod"></div> 

Why doesn't this jquery line set the value of the cloned input to 5?

 var row = $('#xrod').clone(); row.find('.yrod') .val(5)​; $('#xrod').append(row.html()); 
+4
source share
2 answers

try the following:

 var xrod = $("#xrod"); var row = xrod.clone(); row.appendTo(xrod).find('.yrod').val(5)​; 

Note that you do not need to add html, you can add a jquery object

+1
source

common mistake

 var row = $('#xrod').clone(); row.find('.yrod').val(5)​; // you think you change the value of the cloned object but you don't $('#xrod').append(row.html()); 

you are missing a link

 var row = $('#xrod').clone(); row = row.find('.yrod') .val(5)​; $('#xrod').append(row); 

also you do not need to add .html() to the string.

+3
source

All Articles