javascript - adding a class with multiple links in jquery -


i'm adding background image third party links filter function this

$("a").filter(function () {                 var ignorelink =         this.hostname == location.hostname // disregard same domain         || this.href.match(/^(mailto|tel|javascript)\:/)                 return !ignorelink;             }).addclass("externalanchor").attr("target", "_blank"); 

the above code works fine have requirement saying of links should internal ex:

<p><a href="https://www.google.com/" target="_blank">email url</a></p> <p><a href="https://github.com/" target="_blank">google</a></p> <p><a href="https://www.w3schools.com" target="_blank">google</a></p> <p><a href="https://www.codecademy.com" target="_blank">google</a></p> 

my question how add class links separate out dom change jquery.

you can use attribute contains selector

$("a[href*='google.com'], a[href*='w3schools.com'], a[href*='codeacademy.com']").addclass('no-external'); 

Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -