javascript - How do I loop through divs and find the nearest span and add different things to each span? -
for example had following html:
<div class="div-style">div text</div> <span>span text</span> <div class="div-style">another div</div> <span>another span</span> <div class="div-style">hello</div> <span>world</span>   now want is: (using jquery)
- go each 
<div>class 'div-style' - find following 
<span> - append current 
<span>'s text span (in effect repeating span text within span text, first span display 'span textspan text') 
$('.div-style').each(function(){  var t = $(this).next('span').text();    $(this).next('span').text($(this).next('span').text() + t);      })  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div class="div-style">div text</div> <span>span text</span>  <div class="div-style">another div</div> <span>another span</span>  <div class="div-style">hello</div> <span>world</span>  try this
Comments
Post a Comment