Tired_Man
Tired_Man

Reputation: 97

Button onclick jquery not working

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

Answers (4)

sergioBertolazzo
sergioBertolazzo

Reputation: 604

I use this code:

url = "http://wwww.bbc.co.uk";
window.open(url, '_blank');

works for me

Upvotes: 0

Dinesh undefined
Dinesh undefined

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

prasanth
prasanth

Reputation: 22490

Read this link below:

window.location.href

 $('li#menu-item-28').on('click', function(event) {
    event.preventDefault();
        //alert('Clicked');
    window.location.href = "http://www.bbc.co.uk";

    });

Upvotes: 1

aPa
aPa

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

Related Questions