hyperlink - Jquery to change links to _blank if they don't start with a specific url/domain -
i know $("a[href='http://testtesttest.org/']").attr("target", "_blank");
find , change links match test url, i'd know how change links not match url. links take users other webites -- outside links
you can use :not
:
$("a:not([href='http://testtesttest.org/'])")
if want select don't start url, have use attribute starts selector ^=
:
$("a:not([href^='http://testtesttest.org/'])")
you mention:
essentially links take users other webites -- outside links
that depends on how consistent structure of internal urls is. e.g. previous shown selector select links such as
<a href="/images">images</a>
or
<a href="foo/bar">bar</a>
which internal. if every internal link starts domain name, fine. if not, either have possibility adjust links, have consistent structure, or use selector:
$("a[href^='http']:not([href^='http://testtesttest.org/'])")
this make sure links absolute , relative urls not selected.
if have links other protocols, such file:
, becomes more involved.
Comments
Post a Comment