Reputation: 5865
New to jQuery here. I've found several web pages that come close to what I'm trying to do, but not quite. Actually, I think the following is supposed to actually work, but it's saying:
[@href^="http://"]
is not recognized (syntax error). Any help?
$(document).ready(function() {
$('a[@href^="http://"]').filter(function() {
return this.hostname && this.hostname !== location.hostname;
}).attr('target', '_blank');
});
Thanks.
Upvotes: 5
Views: 2523
Reputation: 5420
No need for the @ symbol. Other than that, you're golden.
$("a[href^='http://']")...
Upvotes: 9