tags:

views:

119

answers:

6

Can anyone tell me of a way to open all links within an id in a new window?

+2  A: 

Put this in the head:

$(function () {
    $('#selector').attr('target', '_blank');
})
Nick Spiers
Perfect! Thank you!
Jackson
So accept the answer?
Gausie
A: 

Try this:

$('#myId').click(function(){
    this.target = "_blank";
});

Regards, Paul Peelen

Paul Peelen
A: 

Is it a single function that will open all the hyperlinks within an ID in new windows? That's what I thought. :P

$("#some_id a").each(function (i) {
    window.open(this.href);
  });
o.k.w
A: 
$('#id a').click(function() {
    this.target = "_blank";    
}
Jimmeh
A: 

If you say "all links" ,that i understand that any of specific link (e.g. may be more than one on the page) should guide to blank page.

For this case, you may do all needed links,that guide to blank page ,with specific id and dynamically generated postfix, e.g.:

link_1, link_2 etc.

so the script will look like:

var linkId = "[id*=" + "link_]";
$(linkId).attr('target', '_blank');

here is regexp used.

sergionni
A: 

I'd do it like this:

$('#myId a').click(function()
    window.open(this.href);
    return false;
});
jammus