Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to output a span into a li with jquery?

I have a ul that contain 2 li each of them have a text and a span that contain text like this

<ul>
   <li>Erbil<span>text-1</span></li>
   <li>Sulymany<span>text-2</span></li>
</ul>

i want to remove Erbil and Sulymany from the code with jquery.... I'm used this in jQuery

$('li').each(function () {
    $('li').html($('span'));
});

but the result like this..

text-1text-2text-1text-2
text-1text-2text-1text-2

how to output only a span without repeating?

like image 419
Pshtiwan KarDo Avatar asked Dec 05 '25 04:12

Pshtiwan KarDo


1 Answers

Try to use .html() and its receiver function to accomplish your task,

$('ul li').html(function(){
  return $(this).find('span');
});

DEMO

like image 197
Rajaprabhu Aravindasamy Avatar answered Dec 07 '25 17:12

Rajaprabhu Aravindasamy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!