Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
-5
rated 0 times [  1] [ 6]  / answers: 1 / hits: 30013  / 11 Years ago, thu, october 3, 2013, 12:00:00

I got like;



<p>Variable Text</p>


And I want to it to be;



<p>Variable <span>Text</span></p>


Is this possible by a javascript function? / or jQuery.



Oh yeah, and the p-element got an ID and the text inside the p-element is variable but always consists of 2 words. I want a span around the last word of the text by a javascript function.


More From » css

 Answers
36

Try this



var txt = Hello bye;
var dataArr = txt.split(' ');

var paragraph = document.getElementById(pid);
paragraph.innerHTML = dataArr[0]+ <span>+dataArr[1]+</span>;


Here is a demo


[#75264] Wednesday, October 2, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
miles

Total Points: 256
Total Questions: 111
Total Answers: 104

Location: Benin
Member since Fri, Mar 24, 2023
1 Year ago
;