external links with jquery

external links target with jquery

$(document).ready(function () {
    // Creating custom :external selector
    $.expr[':'].external = function (obj) {
        return !obj.href.match(/^mailto\:/) && !obj.href.match(/^javascript\:/)
                        && (obj.hostname != window.location.hostname);
    };

    // Add 'external' CSS class to all external links
    $('a:external').addClass('external');
});

Demo


external links with jquery external links with jquery Reviewed by Bhaumik Patel on 9:01 PM Rating: 5