How can I trigger my own (href) click of a tag using jQuery or mootools?

In jQuery trigger ('click') and press () only seem to fire the onclick event. I want to simulate a tag click without an onclick event.

What I'm trying to achieve is to display the lightbox on landing. A lightbox is attached to a tag to be clicked.

Any ideas?

+3
source share
6 answers

still to answer your original question, at least regarding mootools: you can simulate a click / fire set by a function to handle it (if any):

$("someid").fireEvent("click");
+2
source

onclick - , . , .

-, . return false;, e.preventDefault(), , e.stopPropagation() e.stopImmediatePropagation(), .

, lightbox "" .

+1
 //I use, when want show image in lightbox by original image or thumbnails list   

 //simulate click on lightbox image by click another place with same image url (hack pro kliknuti na spravne url lightboxu)
$('#simulate_click').click(function(event){

    //get url from simulate link (zjistime url odkazu)
    var odkaz = $(this).attr("href");

    //look for real lightbox link with the same url (najdeme lightbox odkaz)
    var lightOdkaz = $('#rc-carousel ul li a[href="'+odkaz+'"]');

    //simulate clik on that lightbox link (klikneme na nej)
    lightOdkaz.trigger("click");

    //stop propagation of click on original link (zabranime propagaci)
    return false;
     //event.stopPropagation();
    });
+1

:

window.location = $('a#go').attr('href')

0

. Slimbox mootools .

0

JavaScript, . Slimbox , !

0

Source: https://habr.com/ru/post/1721312/


All Articles