I’m quite new here, and just recently discovered jQuery.
I have a list:
<ul id="tagcloud">
<li>Strategic Planning Process,Preparing for Changes,</li>
<li>Effective,Enrollment Managers,Effective Enrollment Managers,</li>
<li>Enrollment Program,</li>
<li>Next Generation,Diversity,Future enrollment,</li>
<li>Annual Admissions Plan,</li>
</ul>
Now, what i want to do, is basicly replace all the “,” with </li><li> and, of course, get rid of the last “,” not to have empty <li>
I think its gonna be something like:
$('pre').html(function() {
return this.innerHTML.replace(",", "</li><li>");
});
But it doesnt work. I’m probably thinking wrong…
$('pre')selectspreelements. In addition,replace[docs] only replaces the first occurence of a string unless provided a regular expression with global flag.I guess you want
DEMO
Alternatively, to not create empty
lielements (which happens if the comma is at the end), you can take the text only:DEMO
Further reading: