简体   繁体   中英

remove specific text from html page using jquery

I have an automated <li> list created in my page with some text as link:

<ul class="continents">
   <li class="link"><a href="#">hotels in USA</a></li>
   <li class="link"><a href="#">hotels in Europe</a></li>
   <li class="link"><a href="#">hotels in Asia</a></li>
   <li class="link"><a href="#">hotels in Africa</a></li>
</ul>

I want to remove only the "hotels in " from the links. can I do it with jquery?

Try .text( function(index, text) )

.replace()

Fiddle Demo

$('.continents a').text(function (_, old){
    return old.replace('hotels in ', '');
});

try this

$(".continents li>a").each(function () {


   console.log($(this).html().replace('hotels', ''));
});

Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM