I am trying to create a custom confirm dialog when user clicks on a link with specific class. It's pretty trivial, but the catch is, if the user clicks on the "Confirm" button in the dialog (Using Twitter Bootstrap 3), I want to trigger click on the same link, but this time instead of showing dialog, to follow the link.
Everything is well up to the point when I want to trigger a click event on the <a> tag with some parameters. Here is very simplified sample of what I want to achieve
Html:
<a class="initial" href="http://yell.com">click me</a>
<div class="dialog hidden">
<a href="#">Click me again</a>
</div>
JavaScript:
$(document).on('click', 'a.initial', function(e, forced){
//return true;
if(typeof(forced) !== 'undefined' && forced === true){
$(this).addClass('clicked');
console.log('Clicked');
return true;
} else{
e.preventDefault();
$(this).removeClass('clicked');
$('div').removeClass('hidden');
}
});
$(document).on('click', 'div.dialog a', function(e){
$(this).parent().addClass('hidden');
$(this).parent().prev().trigger('click', [true]);
});
Here is JSFiddle sample
As you can see, if the second link is clicked, the first link is colored in red, as well as console.log triggers message, but then the link doesn't follow the url. Unfortunately, I don't see any error or warning which could give me some clue. I know I can use window.location = $(element).attr('href'), but I am wondering why it is not working in the described way?
Any help is much appreciated.