Remove specified text from variable using jQuery

I have a variable called position where I want to delete part of the text. The exact text I want to remove is contained in the title variable.

 var title = $(currentLi).find('img').attr('alt'); var position = $(currentLi).find('span').text(); 

To just clarify, I create a variable called position containing the text, I want to delete all the text that matches the text inside the title variable.

Thanks for the help of anyones.

+4
source share
4 answers

Try the following:

 var title = $(currentLi).find('img').attr('alt'); var span = $(currentLi).find('span'); var replaced = span.text().replace(title, ''); span.text(replaced); 
+2
source

I made a jsfiddle for you that does the job. Try using .replace();

http://jsfiddle.net/P5tb8/

+2
source

Just replace javascript. Just add this after your existing code and believe that it should return what is in the variable position minus what you have in the header.

 position = position.replace(title, ""); 
+2
source

Source: https://habr.com/ru/post/1390071/


All Articles