简体   繁体   中英

Open link in new tab from pop-up using Jquery

I am trying to open up a new page using a link in a pop-up in a new tab. I am new to Jquery so I am unsure if this is on the correct track:

 $('.modal-content a').click(function() {
      alert( "Handler for .click() called." );
      a.set('target', '_blank');
    });

HTML:

<div class="modal-content">
    <div>
        <h1>This is  pop-up</h1>
    </div>
<p><a href="www.google.co.nz">Open in new window</a></p>
</div>

"modal-content" is the class name of the pop-up div. I am not sure if I am calling the link element correctly. There is no unique identifier on the tag.

Any help will greatly be appreciated.

.attr()

$('a').attr('target', '_blank');

or .prop()

$('a').prop('target', '_blank');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM