Reputation: 97
I am trying to get a button class to be clicked and redirected to a new page.
But it is not working for me.
Here is my code:
$('li#menu-item-28').on('click', function(event) {
event.preventDefault();
//alert('Clicked');
url = "http://wwww.bbc.co.uk";
$(location).attr("href", url);
});
Any help would be appreciated :)
Upvotes: 2
Views: 441
Reputation: 604
I use this code:
url = "http://wwww.bbc.co.uk";
window.open(url, '_blank');
works for me
Upvotes: 0
Reputation: 5546
try window.location.href = url;
$(document).on('click','li#menu-item-28',function(event) {
event.preventDefault();
url = "http://www.bbc.co.uk";
window.location.href = url;
});
Upvotes: 2
Reputation: 22490
Read this link below:
$('li#menu-item-28').on('click', function(event) {
event.preventDefault();
//alert('Clicked');
window.location.href = "http://www.bbc.co.uk";
});
Upvotes: 1
Reputation: 257
if your element generate dynamically , you should listen on document :
$(document).on('click','li#menu-item-28',function(){
url = "http://wwww.bbc.co.uk";
window.location.href = url;
});
Upvotes: 0