javascript - Do preventDefault and then do default behavior -
i have requirement in single page application project, need change page's section when click on anchor tag based on provided href
attribute. this:
<a class="page-click" href="#showpeople/1">open</a>
this anchor in popup on page. so, whenever click on anchor tag, anchor should close popup , change window location
http://www.example.com/#showpeople/1
now, anchor changing url (which default) not closing popup.
when researched found anchors, should use e.preventdefault()
remove default behavior. in case, need both default behavior custom behavior (closing popup).
i found link has similar requirement thing attaching event dynamically.
$(document).on('click', '.page-click', function (e) { // e.preventdefault(); // code here });
and if somehow succeeded unbind
event specific clicked anchor, anchor not close popup, when user opens popup again (since registered event has been removed).
try
$('button').click(function () { $('body').toggleclass('active'); }); $(document).on('click', 'a.page-click', function (e) { e.preventdefault(); var $this = $(this); $('.popup').hide('fast', function() { window.location.href = "http://example.com/" + $this.attr('href'); }); });
Comments
Post a Comment