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.

js fiddle

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>') ); 

demo


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -