javascript - Change the first value of a title -


i need change first value of title. did don't know if it's best way it.

html:

<div title="title have change"> div here </div> 

js:

$("div").click(function(){      var title =  $(this).attr('title').split(' ')[0];         /*            title getting first value (title), so,             need change him.        */         // better way ?        if(title == "title"){              $(this).attr("title", "changed have change");        } }); 

can change part of title, instead that?

keep of parts of title around. change first part, join parts form new title.

$("div").click(function(){      var parts =  $(this).attr('title').split(' ');         /*            change part[0]        */         // put parts        $(this).attr("title", parts.join(" " )); }); 

alternatively, if transformation relatively simple (say remove first word if it's title), use regular expression.

$("div").click(function(){      var newtitle =  $(this).attr('title').replace(/^title /,''); // space important      $(this).attr("title", newtitle); }); 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -