Here is a good example.
function linkify(inputText) { var pattern = /([-a-zA-Z0-9@:%_\+.~#?&\/\/=]{2,256}\.[az]{2,4}\b(\/?[-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)?)/gi; var replacedText = inputText.replace(pattern, '<a href="$1" target="_blank">$1</a>'); return replacedText; } var div = $('div'), txt = div.text(), newTxt; newTxt = linkify(txt); div.html(newTxt);
For you it can be rewritten for example like this:
$(function(){ $('a').each(function() { var a = new RegExp('/' + window.location.host + '/'); var e = /([-a-zA-Z0-9@:%_\+.~#?&\/\/=]{2,256}\.[az]{2,4}\b(\/?[-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)?)/gi var b = new RegExp(e); if (this.href && b.test(this.href) && !a.test(this.href)) { $(this).css({ "backgroundColor" : "rgba(255, 0, 0, 0.27)", "padding" : "3px", "border" : "1px #f00 dashed", "opacity" : "1 !important", "display" : "inline-block !important" }); } }); })
Here there is a selection of all elements of a , which have an attribute href , and this attribute is a url link that leads to another domain.
<a id="test" href=""></a>? So this code only looks at.hashlinks - it does not look at the item ID. - Regenthttp://orhttps://at the beginning of the link to the check. - Regent