I need to change only the first value of a title. I did something but I don’t know if it’s the best way to do it.
HTML:
<div title="Title that have to be change"> the div is here </div>
JS:
$("div").click(function(){
var title = $(this).attr('title').split(' ')[0];
/*
title is now getting the first value (Title), so,
i need to change only him.
*/
// this is the better way to do this ?
if(title == "Title"){
$(this).attr("title", "Changed that have to be change");
}
});
Can I change just a part of the title, instead to do all that?
Keep all of the parts of the title around. Only change the first part, then join the parts back together to form the new title.
Alternatively, if the transformation is relatively simple (say remove the first word if it’s Title), you could use a regular expression.