Basically, i would like to add a class to a phone number thats inside a <p>
tag with a heap of other text.
The CMS their using won't allow me to add HTML to the content, so i am left with jQuery.
I am trying to write a script that looks for the phone number inside very single <p>
tag, and replaces only the number with no other changes to the surrounding text.
The script i have so far removes the entire <p>
content, and leaves only the phone number, where as i just want to replace the phone number with a span tag and class.
I'm still new to jQuery, so i'm pretty much stuck here,
Here is my script so far:
$("p").each(function () {
if ($(this).is(':contains("(02) 88506226")')) {
console.log('yes');
$(this).html('<span class="phone">(02) 88506226</span>');
} else {
console.log('no');
}
});
Would appreciate any help anyone can offer :]
, then the full replace is fine.
– lod Nov 14 '18 at 01:35