Can I execute a link after a preventDefault()? Can I execute a link after a preventDefault()? jquery jquery

Can I execute a link after a preventDefault()?


$('#myLink').click(function (e) {    e.preventDefault();    ...    if (someCondition) {      //do stuff    } else {        location.href = $(this).attr('href');    }});


Just move the preventDefault inside the if/else statement:

$('#myLink').click(function (e) {    ...    if (someCondition) {        e.preventDefault();        ... code ...    } else {        ... execute the link    }});


Take a look: Jquery Location Href?

Basically you can use window.location.href = 'http://example.com';