tags:

views:

27

answers:

2

The title says it all. Instead of putting "target="_blank" on every link, how can I do it with jQuery?

+2  A: 

Uh, I guess you could do something like this:

$('a.newWindow').click(function() {
    var href = $(this).attr('href');
    if(href.length > 0) {
       window.open(href);
    }
});

Or, just do it the right way:

$('a.newWindow').attr('target', '_blank');
Jacob Relkin
+3  A: 

you don't need jQuery

insert this to your <header>

<base target="_blank" />

see more: http://www.w3schools.com/TAGS/tag_base.asp

est
Target is deprecated.
Radu
@Radu No it's not, check this out http://www.w3.org/TR/html5-diff/#new-attributes
est
@est Ah, wasn't aware they're adding it back in HTML5. Thanks.
Radu