Tom
Tom

Reputation: 1068

How can I modify this code to just affect normal links? (basic jQuery)

$(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 :) )

Upvotes: 1

Views: 80

Answers (1)

brendan
brendan

Reputation: 29976

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

Upvotes: 4

Related Questions