Search code examples
javascriptjqueryhtmllightboxlightbox2

How to call lightbox from outstanding link?


Does somebody know, how to call a lightbox from an custom link?

Example:

$('#price1 a').lightBox(); //in the header

Now I want to click a custom link somewhere on the page.

<a href="#" class="price1">Link to lightBox</a>

And images in a div (until link clicked they are not visible)

<div id="price1" style="display: none;">
    <a href="../images/img1.jpg"></a>
    <a href="../images/img2.jpg"></a>
    <a href="../images/img3.jpg"></a>
</div>  

Could somebody please help.

Best Regards!


Solution

  • You can try jQuery events binding:

    $(".price1").bind("click", function() {
        $("#price1 a:first").click();
    };
    

    This way, when you click on link with class "price1", jQuery will emulate clicking on first link in div with id "price1".