javascript - Wrapping a split string's substrings in an element -


how use javascript/jquery select $('td.created') , split html on <br>, wrap each section in span tags (so can add class span:first in order style it).

the format of string returned $('td.created').html() like

posted user123 <br> posted on 1/2/12 @ 4:15pm

possible universal solution (works not 2 lines):

$("td.created").each(function() {     var text = this.innerhtml.split("<br>");     (var = 0; < text.length; i++) {         var span = $("<span />").html(text[i]);         if (i == 0) span.addclass("first");         span.appendto("#element");     } });​ 

demo: http://jsfiddle.net/7xqal/


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -