LatinCanuck
LatinCanuck

Reputation: 463

Prevent Jquery image tool from running when condition met

'm using a jquery tool called LightBox. Its a tool for displaying images. It works fine but I need to prevent the lightbox functionality from happening if a certain value is returned from an ajax call. Now, this question is not about the ajax call, its about how do I stop LightBox from doing its thing after the link has already been clicked?

This is the link that popups the image using LightBox (it works fine)

<a id="test_id" href="http://localhost/histogram.do" data-lightbox="histogram1"> Click Me </a>

This is my clumsy code to try to stop LightBox from continuing. The alert happens but the lightbox popup still appears right after clicking ok. Any ideas?

$("#test_id").click(function(e){
    alert("hello");
    e.stopPropagation();
})

Upvotes: 0

Views: 119

Answers (1)

jamis0n
jamis0n

Reputation: 3820

That library uses jQuery .on() to bind the click event to the element.

Have you tried e.stopImmediatePropagation() ?

http://api.jquery.com/event.stopImmediatePropagation/

It prevents any other handlers from firing and then calls stopPropagation() to prevent bubbling.

Furthermore, to prevent the element from following the href link on click, you can use e.preventDefault()

http://api.jquery.com/event.preventDefault/

Upvotes: 1

Related Questions