paul
paul

Reputation: 13471

Check that click event already exist on JQuery 1.11.1

I´m looking for all internet and I cannot find a situation like mine.

I have a jsp(lets call it A.jsp) with an import javascript, which has a onDocumemntReady. In that documentReady I bound an click event for a class element of my A.jsp.

Now The issue is that I have another page with a loop where I iterate and include n A.jsp.

So now what´s happening is that I add this n pages on the DOM and after finish the onDocumentReady is call it for everyone. So what I want to do is just create the "click" events once. Looking on google I cannot find a way to check if the event already exist for JQuery 1.11.1. Any idea.

Regards.

Upvotes: 1

Views: 571

Answers (1)

Vijay
Vijay

Reputation: 3023

why not to simply "Off" and "On" events.

example:

$(selector).off('click').on('click',function(){//do something});

or If you only want one event per selector, use one:

$(selector).one('click',function(){//do something});

NOTE: For your curiosity, there are plugins avaiable which are supported across required jQuery version. https://github.com/Inducido/jquery-handler-toolkit.js

Upvotes: 2

Related Questions