Reputation: 3
My jquery code is conflicting with my links, causing them not to open in a new window "target=_blank"?
onReady:function(){
$('a').click(function(event) {
event.preventDefault();
CookieControl.setConsent(true);
CookieControl.closeAndHide();
window.location = $(this).attr('href');
});
},
The affected links are <a href="www.google.com" target="_blank">Link</a>
Upvotes: 0
Views: 40
Reputation: 8592
Rather than tying your event to all <a>
tags, add a class to the link or links you wish to target, like so:
<a class="lnkSpecial" href="http://www.google.com" target="_blank">Link</a>
Then bind your event to that class:
$('.lnkSpecial').click(function(event) {
event.preventDefault();
CookieControl.setConsent(true);
CookieControl.closeAndHide();
window.location = $(this).attr('href');
});
This will prevent the default action only on the link or links with the class.
Upvotes: 0
Reputation: 65808
The very first thing your callback does is cancel the event!
event.preventDefault();
Upvotes: 1