user2403131
user2403131

Reputation: 43

JQuery - I need to check if a button was clicked

I need to check if a button was clicked so you can make a condition with "if"

PS: There are infinitely many elements, each with a knob. Verification should be dynamic

My Button Event:

$(btnClose).click(function () {
     $(this).parent().remove();
     $("#modalProperties").hide();
});

My click element event:

$(".clonado").live("click",function(){
     $("#modalProperties").show();
});

Problem: The problem here is that the elements are inside a div and after remove them should I closes one modal The problem is that this modal is opened by clicking on the element What happens is that it opens and then closes because I clicking on the element start the action to close and the open modal.

Anyone know what can be done?

I can know if it is the first time you started the event?

Upvotes: 0

Views: 107

Answers (2)

Bharat Chodvadiya
Bharat Chodvadiya

Reputation: 1650

Use .on event and also use .ready event like this.

$(document).ready(function () {

 $(btnClose).on('click',function () {
   $(this).parent().remove();
   $("#modalProperties").hide();
 });

 $(document).on("click",".clonado",function(){
   $("#modalProperties").show();
 });

});

Upvotes: 0

Luke Cousins
Luke Cousins

Reputation: 2156

Assuming the problem is to do with bubbling, fix it like this:

$(btnClose).click(function (event) {
     event.preventDefault();
     $(this).parent().remove();
     $("#modalProperties").hide();
});

and

$(".clonado").click(function(event){
     event.preventDefault();
     $("#modalProperties").show();
});

Upvotes: 1

Related Questions