I want to all numbers in my html text have different font-size with other character (or different font-family or different font-weight or ...). How to define numbers character? Is this possible with jquery? Can you help me?!
jQuery val() Method The val() method returns or sets the value attribute of the selected elements. When used to return value: This method returns the value of the value attribute of the FIRST matched element.
To get the value of div content in jQuery, use the text() method. The text( ) method gets the combined text contents of all matched elements. This method works for both on XML and XHTML documents.
Answer: Use the jQuery text() method You can simply use the jQuery text() method to get all the text content inside an element. The text() method also return the text content of child elements.
Using regex you match the numbers an wrap them in a span with a class. No jquery needed.
string.replace(/\d+/g,function(match){
return "<span class='number'>" + match + "</span>"})
You can control the number design with css:
.number{
color:red;
}
Since you asked for a JQuery solution, I transformed @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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With