split - Find first word in html and replace -


i have following construct:

<h1>   <span>   </span> </h1> 

.... and

<div id="tourname">riding trip arround volcano</div> 

now div id filled php function , h1 looks this:

<h1>    <span>riding</span>    trip arround volcano </h1> 

i managed fill h1 using function:

 $("h1").html($("#tourname").html()); 

but have no idea how split string 2 parts , fill 1 part span , rest behind /span

can give hint ?

many thanks

you can in 2 ways . 1 - when writing using php , can create span first word. 2 - using jquery. can see below code using jquery

  $(document).ready(function(){     var text = $("#tourname").html();     var firstword = text.substr(0,text.indexof(' ')); // first word      var remaining = text.substr(text.indexof(' ')+1); // remianing words     var final = '<span>'+firstword+'</span> '+ remaining // combining adding <span> around first word     $("h1").html(final);   }); 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -