I have a jquery click event for a bunch of links and one drop-down selector in my MVC view and I preventDefault on them before doing the event, because most of them redirect to a view (the redirect stops my jquery code doesn't it?). After all of my callbacks in my click event, I would like the links and drop-down selector to do their default event so it doesn't just sit on the page like nothing has happened.
Is there an easy way to get all of the links/drop-down to return to default and then programatically click them in jquery? I've tried $(this).click()
and $(this).submit()
and e.click()
and e.submit()
with no luck.
Here is my code
$("input,a,select").not("#SubmitButton").click(function (e) {
e.preventDefault();
console.log("prevented default");
deletePreview($(this));
});
function deletePreview(button) {
console.log("clicked");
//Delete Offer from DB
$.post('@Url.Content("~/")Offer/DeleteJoAnnOffer/?offerId=' + offerID, function (data) {
console.log("finished deleting");
if (button.attr('id') == "CancelButton") {
window.location.href = '@Url.Content("~/")Offer/CreateJoAnn/';
} else {
//DO DEFAULT ACTION HERE
}
});
};
[EDIT]: One more question: If I don't use preventDefault(), my jquery event executes (well the initial part because my console logs "clicked"), but I cannot confirm if the jquery posts are actually executing because the console refreshes on the new page.