Reputation: 24122
Is there a better way than traversing like this?:
$('#part'+rowNumber).parent().parent().next().children('input').val(manufacturer);
The DOM segment in question is:
var html = '<div class="row-fluid">';
html += '<div class="span1"><img title="Remove part." class="pull-right remove-part" width="20px" src="http://www.view.com/public_html/images/icons/minus.png"></div>';
html += '<div class="span1"><input type="number" value="1" class="span12"/></div>';
html += '<div class="span5"><input id="part'+rowNumber+'" type="text" class="span12"/></div>';
html += '<div class="span4"><input type="text" class="span12 last"/></div>';
html += '<div class="span1"></div>';
html += '</div>';
Upvotes: 1
Views: 71
Reputation: 21
You can try using .closest() selector:
$('#part'+rowNumber).closest('.row-fluid').next().find('input').val(manufacturer);
Upvotes: 1
Reputation: 388406
Instead of using .parent().parent(), try .closest(), other than that I don't see anything else
$('#part'+rowNumber).closest('.row-fluid').next().children('input').val(manufacturer);
Upvotes: 1
Reputation: 15709
You can write like:
$('#part'+rowNumber).parents('.row-fluid').next().children('input').val(manufacturer);
Upvotes: 1