Vaughn D. Taylor Vaughn D. Taylor - 1 year ago 57
Javascript Question

How to change all phone numbers on a page to clickable links, excluding a specifically classed element

I want to transform all phone numbers entered through a CMS into clickable phone numbers. Basically, I want this 800-777-0000 to be transformed into this:

<a href="tel:8007770000">800-777-0000</a>

However, I do not want buttons (which are already formatted properly) to be altered. So, this item should remain untouched:

<a href="tel:8007770000" class="button">Call Today</a>

I'm about 99.999% of the way there with my pen on Codepen, but I'm not sure how to exclude elements with a "button" class?



I modified the code below like this:

$.each($('.content-cms').find('p, ol, ul, h2, h3, h4, h5, div:not(.button-row), a:not(.button)'), function(i, value) {

Answer Source

-- EDITED after properly understandment --

If you don't have nested .button elements, this should work:




$.each($(".content-cms").find('*').not('.button'), function(index,value) 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download