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
Post a Comment