Last active
March 21, 2017 16:23
-
-
Save Emuentes/ae77af19749df2477547b0855029f052 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var urlBase = location.protocol + '//' + location.host; | |
var hasNonEmptyHrefAttr = ':not([href=""])'; | |
var doesNotBeginWithUrlBase = ':not([href^="' + urlBase + '"])'; | |
var isNotRelativeUrl = ':not([href^="/"])'; | |
var isNotAnAnchor = ':not([href^="#"])'; | |
var isNotJavascriptLink = ':not([href^="javascript:")'; | |
var externalLinkSelector = 'a' + hasNonEmptyHrefAttr + doesNotBeginWithUrlBase + isNotRelativeUrl + isNotAnAnchor + isNotJavascriptLink; | |
var externalLinks = jQuery(externalLinkSelector); | |
// for reference, the selector string looks like this: | |
// 'a:not([href=""]):not([href^="https://priceline.atlassian.net"]):not([href^="/"]):not([href^="#"]):not([href^="javascript:")' | |
// MULTIPLE "not" pseudo-classes chained means "not(this) OR not(that)" | |
// --> a:not([href="this"]):not([href="that"]) translates to: | |
// NOT <a href="this"></a> OR <a href="that"></a> | |
// ONE "not" pseudo-class with selectors chained INSIDE it means "not (this AND that)" | |
// --> a:not([data-type*="accordion"][data-type*="expand"]) would: | |
// --> exclude <a data-type="module accordion expand"></a> | |
// --> but would include <a data-type="module accordion"></a> <a data-type="module expand"></a> any any other <a> tags. | |
// References: | |
// https://css-tricks.com/attribute-selectors/ | |
// https://css-tricks.com/multiple-attribute-values/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment