0

I've made a card surrounding with an anchor tag and applied a onclick() event on the card using it's id, the click is working fine but the problem here is even if the checkbox, image or button of card gets clicked the click event of the card fires up but I've to use the checkbox and button for another purpose, so is there any way to disable or ignore the click event of the card when the checkbox or the button gets clicked

HTML:

<div id="row" id"myDiv">
    <div class="col-6">
        <div class="card card2"
                style="margin-bottom: 0.5rem !important;"
                id="btnQuoteSummary">
            <div class="row">
                <div class="col-9"></div>
                <div class="col-3">
                    <div class="form-check">
                        <input type="checkbox" name="checkSelect"
                            id="checkSelect1"><label for="checkSelect1"></label>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-4">
                    <div class="card-header">
                        <span class="float-left"><img
                            class="card-img-top insLogo"
                            style="width: 5rem; object-fit: contain;"
                            src="/static/images/86d5b04c-1201-4ef4-b0e8-88503c719e2b.jpg"
                            alt="my image"></span>
                    </div>
                </div>
                <div class="col-4"></div>
                <div class="col-4">
                    <div class="min-width-zero">
                        <button class="btn btn-primary">
                            <span>3,954</span>
                        </button>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-8">
                    <p class="mb-2 text-muted" style="margin-left: 4.5rem;">value</p>
                </div>
                <div class="col-4">
                    <p class="mb-2 text-muted">4.35</p>
                </div>
            </div>
        </div>
</div>

JQuery:

$('#myDiv').on('click', '#btnQuoteSummary', function () {
    alert('card click event fired')
});

Please help me here

Cybertronian
  • 473
  • 1
  • 8
  • 17

4 Answers4

1

You can try below code.

$(document).ready(function(){
  $('#btnQuoteSummary').click(function(event){
        alert('card click event fired');
        event.preventDefault();
    });
});
Pushprajsinh Chudasama
  • 7,772
  • 4
  • 20
  • 43
1

Just off click event for that particular button-through following code,

$('#btnQuoteSummary').off('click');

This will work perfectly.

Kali SPM
  • 137
  • 1
  • 5
0

One option through. CSS

.avoid-clicks {
  pointer-events: none;
}

Or through jQuery:

$( "#btnQuoteSummary " ).click(function( event ) {
  event.preventDefault();
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
0

Try putting these lines in the click event of child elements to disable triggering the click event of parent element

if (!e) var e = window.event;
  e.cancelBubble = true;
  if (e.stopPropagation) e.stopPropagation();

Eg:

 $("your-button-id / your-input-checkbox-id /your-img-id etc").click(function(){
    /*
    code to execute (if any)
    */
    if (!e) var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
 });     
rover cj
  • 61
  • 3