javascript - Using jquery, how can I get this "inner text" of a li element? -


this question has answer here:

i have following html , trying figure out right selector logic read in part. note: can't change html being generated plugin.

  <li class="select2-selection__choice" title="">       <span class="select2-selection__choice__remove" role="presentation">×</span>     ms office  </li>  <li class="select2-selection__choice" title="">       <span class="select2-selection__choice__remove" role="presentation">×</span>     photoshop  </li> 

and trying read out text inside

 <li class="select2-selection__choice"> 

but not including the

 <span class="select2-selection__choice__remove"> 

so example above, looking parse out following text:

 ms office, photoshop 

try

$('.select2-selection__choice').each(function() {     var text = $(this).clone().children().remove().end().text();     console.log(text.trim()); }); 

snippet

$('.select2-selection__choice').each(function() {      var text = $(this).clone().children().remove().end().text();      console.log(text.trim());  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <li class="select2-selection__choice" title="">        <span class="select2-selection__choice__remove" role="presentation">×</span>      ms office   </li>   <li class="select2-selection__choice" title="">        <span class="select2-selection__choice__remove" role="presentation">×</span>      photoshop   </li>


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -