javascript - How to get the value of input from different div in jquery? -
here's html:
<div id="parent"> <div id ="child1"> <div id="subchild1"> <input type="text" name="first" value="3"> </div> </div> <div id ="child2"> <div id="subchild2"> <input type="text" name="second" value="7"> </div> </div> <div id ="child3"> <div id="subchild3"> <input type="text" name="third" value="8"> </div> </div> </div> <div id="result">
here's jquery:
$(function(){ var len = $('#parent > div').length; for(var i=0; < len; i++){ var = $('#subchild'+ [i + 1]).find('input'); $('#result').html(a); } });
it get's last value. tried best here's code can do. maybe can me.
if want values following creates array of values , uses join()
separate them in target div:
var values = $('[id^=subchild] input').map(function(){ return this.value; }).get(); $('#result').html( values.join('<br>') );
Comments
Post a Comment