Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
4.9k views
in Web Development by 1 1 2
edited by

I want to change a certain certain text in span title attribute using JavaScript or JQuery to contain only the first part of the title text (before the dash as shown in the attached pic) using javascript function in which I can apply the function to all titles with the same issue in the whole website.

replace certain text in span title attribute using JavaScript?


3 Answers

1 like 0 dislike
by 1 1 2
selected by
 
Best answer

I can change a certain text in span title attribute using JQuery by doing this:

$('span.js-webpart-titleCell').each(function(){
var splitTitle = $(this).attr('title').split('-');
$(this).attr('title', splitTitle[0]); 
}); 

This function works on every span with js-webpart-titleCell class, split its title attribute into two parts (before and after the dash mark), and change the title to only the first part of it.

1 like 0 dislike
by 5 5 8

You can change the title attribute using JavaScript as below

document.getElementsByClassName('ClassName').title = 'your new title'; 

Also, You can change the title attribute using JQuery as below

$('.classname').attr('title', 'your new title');

Hope it helps!

by 1 1 2
0 0
It does help, thank you !
0 like 0 dislike
by 1 1 3

I also suggest the same as Nada did.

$('span.js-webpart-titleCell').each(function(){ var splitTitle =
$(this).attr('title').split('-'); $(this).attr('title',splitTitle[0]);  }); 
If you don’t ask, the answer is always NO!
...