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

  • Home
  • SEARCH
  • 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 8717143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:14:37+00:00 2026-06-13T06:14:37+00:00

EDIT: I learned that using other value than _blank , DOES NOT work on

  • 0

EDIT:

I learned that using other value than _blank, DOES NOT work on mobile browsers to open new windows/tabs.

For example, if you need to open a new window/tab:

  • This works on all browsers, even mobile browsers: target="_blank".

  • This does not work on mobile browsers, but it does work on desktop browsers: target="new".

—

Although I have this one working, I’m not sure if there’s a better way to do it, or if the way I got it is the right/only way.

Basically what I’m doing is replacing all the target="_new" or target="_blank" attribute values to target="nw", this way only one new window is open and in it all other new windows will open in order to not overwhelm the user with multiple windows.

I’m also adding a “Opens in a new window” title="" attribute.

So the solution I created is this one:

$("a[target='_blank'], a[target='_new']").attr('target','nw').attr('title','Opens in a new window');

Notice the two .attr(); methods.

Is this the correct way to add two attributes to an element?

I tried .attr('target','nw','title','Opens in a new window') but it didn’t work.

The reason I ask is because of the DYR (Don’t Repeat Yourself) principle, so if I can improve the code I have, great, if not, then it is what it is.

Thanks.

  • 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-06-13T06:14:38+00:00Added an answer on June 13, 2026 at 6:14 am

    Should work:

    .attr({
        target:"nw", 
        title:"Opens in a new window",
        "data-value":"internal link" // attributes which contain dash(-) should be covered in quotes.
    });
    

    Note:

    " When setting multiple attributes, the quotes around attribute names are optional.

    WARNING: When setting the ‘class’ attribute, you must always use quotes!

    From the jQuery documentation (Sep 2016) for .attr:

    Attempting to change the type attribute on an input or button element created via document.createElement() will throw an exception on Internet Explorer 8 or older.

    Edit:
    For future reference…
    To get a single attribute you would use

    var strAttribute = $(".something").attr("title");
    

    To set a single attribute you would use

    $(".something").attr("title","Test");
    

    To set multiple attributes you need to wrap everything in { … }

    $(".something").attr( { title:"Test", alt:"Test2" } );
    

    Edit – If you’re trying to get/set the ‘checked’ attribute from a checkbox…

    You will need to use prop() as of jQuery 1.6+

    the .prop() method provides a way to explicitly retrieve property values, while .attr() retrieves attributes.

    …the most important concept to remember about the checked attribute is that it does not correspond to the checked property. The attribute actually corresponds to the defaultChecked property and should be used only to set the initial value of the checkbox. The checked attribute value does not change with the state of the checkbox, while the checked property does

    So to get the checked status of a checkbox, you should use:

    $('#checkbox1').prop('checked'); // Returns true/false
    

    Or to set the checkbox as checked or unchecked you should use:

    $('#checkbox1').prop('checked', true); // To check it
    $('#checkbox1').prop('checked', false); // To uncheck it
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: iam using ajax to load text in my content that is why onload
I have a variable that is not supposed to change its value after it's
Just today learned that one of my websites, TwitPeek.net, is not rendering properly in
I learned that one of the motivation for copy constructor using is to avoid
Edit: Lesson learned: set the orientation or stuff might not show up. As per
I am using modalbox for a modal window to submit forms that I learned
Edit: I've learned much since the posting of this question, and so I have
EDIT: I don't want to delete the post because I have learned a lot
EDIT: I was an idiot. I simply had an image that was vertically long,
EDIT: See my answer below--> I am wanting to have a view that when

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.