Trying to replace text in a paragraph - but breaking other <p> tags on page
Hi guys!
This is my first post here on this forum. I've searched around here and can't seem to find the answer to my particular issue.
So, the issue I'm battling is probably elementary for most folks here. What I'm trying to do (and failing at) is replace a phone number wherever it appears in paragraphs across a website. While I've been able to get the .replace to work, somehow it is breaking other elements on the page(s).
For example, on a blog post page, it nukes the links for the blog author and for the 'Leave a Comment' link that appears right below the blog post title.
Additionally, it is breaking the markup for a couple of buttons that live in the sidebar of pages. What once was a blue button linked to whatever content, gets stripped of its styling and link and becomes just a bit of text.
So, below I've pasted my code and a link to a page for you guys to have a look at as an example. This site is a WordPress site running on a Genesis child theme.
Keep in mind all I want to do is change the phone number in paragraphs axcross the site. Nothing more. I've had no problem targeting specific divs and classes in other parts of the site and got them to work without trouble. It's just these paragraphs that are giving me a fit and breaking other elements on the pages.
Link to page:
http://1ohio.us/articles/
CODE:
- jQuery(function($) {
// NUM SWAP
$('p').not('.site-title').each(function() {
if (/800-218-4243/g.test($(this).text())) {
$(this).text($(this).text().replace(/800-218-4243/g,
'844-853-7373'));
}
});
$('p').not('.site-title,').each(function() {
if (/330-836-0210/g.test($(this).text())) {
$(this).text($(this).text().replace(/330-836-0210/g,
'844-853-7373'));
}
});
});