jquery trigger or click not working? -
i struggling why can't trigger or click work?
here js:
$(document).ready(function () { function libertypop(){ var popup = jquery("#lightbox-30835684809970"); popup.click(); popup.trigger('click'); console.log("should work"); } libertypop(); });
this should triggering click on anchor:
<a id="lightbox-30835684809970" style="cursor:pointer;color:blue;text-decoration:underline;"> liberty pop-up </a>
in page, when click on link, pop appear, don't understand why jquery 'trigger' or 'click' not doing same?
if want trigger native click event of anchor tag, use js event:
var popup = jquery("#lightbox-30835684809970")[0]; //<< [0] retruns dom node popup.click();
but didn't have setted attribute href, nothing!
if want trigger click handler attached using jquery, first set one.
using code:
$(document).ready(function () { function libertypop(){ var popup = jquery("#lightbox-30835684809970"); popup.on('click',function(){ console.log("works!"); }).click(); } libertypop(); });
Comments
Post a Comment