jquery - How to split string containing comma using span tag -
there string containing tags separated comma:
<div class="article" id="1"> <span class="tags">dog, cat, bird, pig</span> </div> <div class="article" id="2"> <span class="tags">asia, africa, australia, europe</span> </div> ....
i wrap each item using span tag within tags class each of them can individually styled this
<span class="tags"><span>dog</span><span>cat<span>...</span>
$('.tags').html($('.tags').html().split(', ').map(function(el) {return '<span>' + el + '</span>'}))
fiddle here
Comments
Post a Comment