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)

  1. go each <div> class 'div-style'
  2. find following <span>
  3. 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

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -