Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3798114
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:31:07+00:00 2026-05-19T13:31:07+00:00

I know that $(a[href=’http://testtesttest.org/’]).attr(target, _blank); will find and change all links that match the

  • 0

I know that $("a[href='http://testtesttest.org/']").attr("target", "_blank"); will find and change all links that match the test url, but I’d like to know how to only change the links that do NOT match that URL. Essentially links that would take users to other webites — outside links

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T13:31:08+00:00Added an answer on May 19, 2026 at 1:31 pm

    You can use :not:

    $("a:not([href='http://testtesttest.org/'])")
    

    If you want to select all those that don’t start with this URL, you have to use the attribute starts with selector ^=:

    $("a:not([href^='http://testtesttest.org/'])")
    

    You mention:

    Essentially links that would take users to other webites — outside links

    That depends on how consistent the structure of internal URLs is. E.g. the previous shown selector would also select links such as

    <a href="/images">Images</a>
    

    or

    <a href="foo/bar">Bar</a>
    

    which are clearly internal. If every internal link starts with your domain name, than it is fine. If not, you either have the possibility to adjust those links, to have a consistent structure, or to use another selector:

    $("a[href^='http']:not([href^='http://testtesttest.org/'])")
    

    This will make sure that links with absolute and relative URLs are not selected.

    If you also have links with other protocols, such as file:, it becomes even more involved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If we know that we can use var link = $('a[href=http://google.com]'); when we want
I am trying to write a script that will find all <a> tags whose
I know that in Javascript document.location.href = #my_id tells the browser to display the
I know that this line of code will make the cell text-wrap: $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setWrapText(true); 'D1'
I know that I can target elements which have a specific attribute in CSS,
I know that question was discussed plenty of times, but i tried all suggestions
is it possible to have <a href=index.php > click </a> that doesn't change page
I know to use Html.ActionLink() to render textual <a href...> links to actions. How
i know that ie6 can only do hover on a href element. but i
I know that Phonegap has an event for back button, but it's only available

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.