How to apply CSS only to numbers in paragraphs without wrapping numbers in span
s?
<p>Text and numbers: 123</p>
<p>123 and text</p>
Are there any selectors? In jQuery, maybe. Or somehow parse it using javascript...
Expected result:
How to apply CSS only to numbers in paragraphs without wrapping numbers in span
s?
<p>Text and numbers: 123</p>
<p>123 and text</p>
Are there any selectors? In jQuery, maybe. Or somehow parse it using javascript...
Expected result:
You can't do this with only CSS. Since you also marked your question with a jQuery tag, you can however do it this way:
$('p').html(function(index, value) {
return value.replace(/(\d+)/g, '<span>$1</span>');
});
There is no way to do what you want without wrapping the desired text strings in elements, like spans or anything else.
With jQuery:
(function($) {
$(function() {
$('p').each(function() {
var el = $(this),
html = el.html();
html = html.replace(/(\d)/gi, "<span class='numbers'>$1</span>");
el.html(html);
});
});
})(jQuery);
try something like:
$('p').html(function(index, value) {
return value.replace(/(\d+)/g, '<span class="here_you_class">$1</span>');
});