Define numbers in html text using jquery

I want all the numbers in my html text to have a different font size with a different character (or another font or another font or ...). How to determine the symbol of numbers? Is this possible with jquery? Could you help me?

+6
source share
2 answers

Since you asked for a jQuery solution, I converted @ raam86's answer to jQuery, it looks like this:

$("div").html($("div").text().replace(/\d+/g, function(m){ return "<span class='number'>" + m + "</span>" })); 

Demo

+2
source

Using a regular expression, you match numbers that wrap them in the gap with the class. No jQuery required.

  string.replace(/\d+/g,function(match){ return "<span class='number'>" + match + "</span>"}) 

You can control the design of the number with css:

  .number{ color:red; } 

Demo

+3
source

Source: https://habr.com/ru/post/949717/


All Articles