tags:

views:

35

answers:

2

I can't get it to work.

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

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

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

$('#xrod').append(row.html());
+1  A: 

try this:

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

note that you dont need to append the html you can append a jquery object

Darko Z
this is what I was really trying to do, but you put me where I needed to go.
polyhedron
http://www.jsfiddle.net/9swsS/
polyhedron
+4  A: 

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 lack reference

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

$('#xrod').append(row);

also you don't need to add .html() to row.

rob waminal