views:

43

answers:

1
$(document).ready(function(){

    $("a").click(function() {
        $("#content").load($(this).attr("href"));
        window.location.hash = $(this).attr("href");
        return false;
    });

});

So I use this code to make all links load in the div (content). But I want all links that have a target of _blank (new page), to open up in a new page - as their default behaviour. How can I do this?

Cheers in advance - (I'm a jQuery noob :) )

+4  A: 

I think this should do it:

$(document).ready(function(){
$("a[target!='_blank']").click(function(){

$("#content").load($(this).attr("href");

window.location.hash=$(this).attr("href");
        return false;
    });
});

Replaced:

$("a").click(function(){...}

With:

$("a[target!='_blank']").click(function(){...}

http://docs.jquery.com/Selectors/attributeNotEqual#attributevalue

brendan
Brilliant, cheers! + thanks for the speeeedy reply.
Tom
Tom
I believe in that case you want to chain them together like this: $("a[target!='_blank'][target!='_top']").click(function(){...}
brendan
perfect, thanks!
Tom