Jquery Toggle Prevent default on a link -
i displaying links on website.
when user clicks on link, don't want them go url immediately. instead, inline pop-up box* should appear disclaimer. user can click on link second time go url (and hide disclaimer).
i know can use prevent default disable default action of link (so doesn't take user anywhere).
and know can use toggle() show/hide pop-up box.
however, not sure how can toggle prevent default.
here jquery code (js fiddle here)
(function($) { $(document).ready(function() { "use strict"; $(".ui-popbox a").click(function(e) { e.preventdefault(); $("[class^='ui-popbox-']").fadetoggle(); }); }); })(jquery);
by "inline pop-up box" referring box appears inside html document. don't mean pop-up window.
you can pass data object event handler check if disclaimer popped or not in jquery follow:
$(".ui-popbox a").click({popped: false}, function (e) { if (!e.data.popped) { e.preventdefault(); $("[class^='ui-popbox-']").fadetoggle(); e.data.popped = true; } });
the value of object kept between events.
Comments
Post a Comment