PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 2, 2022

[FIXED] How to split string containing comma using span tag

 August 02, 2022     css, html, html-table, jquery     No comments   

Issue

There is a string containing tags separated by 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 would like to wrap each item using span tag within the tags class so that each of them can be individually styled like this

<span class="tags"><span>Dog</span><span>Cat</span>...</span>

Solution

$('.tags').html($('.tags').html().split(', ').map(function(el) {return '<span>' + el + '</span>'}))

Fiddle here



Answered By - keune
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing