Not a selector, the on() click event doesn't work


Cesar Bielich

i have my html

<tr class="show_ticket_preview">
    <td>
         <a class="ticket_preview_id">A Link</a>
         <p>Some other stuf</p>
    </td>
</tr>

I need to fire the click event on click, trnot when a is <a>clickedtr

$(document).on('click', '.show_ticket_preview:not(.ticket_preview_id)', function() {

But for whatever reason, when I click ticket_preview_idaccording to the code above , the event still fires .

Any ideas?

Chongle

.show_ticket_preview:not(.ticket_preview_id)The selector will select all elements that have a class show_ticket_previewbut no class ,ticket_preview_id , so it doesn't work in your case.

To solve your problem, you can use the event object in the handle and then check if the target has a class ticket_preview_id:

$(document).on('click', '.show_ticket_preview', function(e) {
  if(!e.target.classList.contains("ticket_preview_id")) console.log(1);
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="show_ticket_preview">
    <div>
         <a class="ticket_preview_id">A Link</a>
         <p>Some other stuf</p>
    </div>
</div>

Related


Not a selector, the on() click event doesn't work

Cesar Bielich i have my html <tr class="show_ticket_preview"> <td> <a class="ticket_preview_id">A Link</a> <p>Some other stuf</p> </td> </tr> I need to fire the click event on click, trnot when a is <a>clickedtr $(document).on('click

Not a selector, the on() click event doesn't work

Cesar Bielich i have my html <tr class="show_ticket_preview"> <td> <a class="ticket_preview_id">A Link</a> <p>Some other stuf</p> </td> </tr> I need to fire the click event on click, trnot when a is <a>clickedtr $(document).on('click

Click and selector: no - doesn't work

Alex Why selector: no - doesn't work? After clicking on the red area, open the alert. Why? <div class='content'> <div style="width:200px; height:200px; background:#EEE;"> <div id="click" style="width:100px; height:100px; background:red"></div>

Selector doesn't work with click button effect

Roger_88: I want to change the background color of itemviewholder when it is clicked. For this I tried using "selector" and "state_pressed" on it but it doesn't work. In this test code, I try to test with buttons and linearlayout. I do this because in my real

Selector doesn't work with click button effect

Roger_88: I want to change the background color of itemviewholder when it is clicked. For this I tried using "selector" and "state_pressed" on it but it doesn't work. In this test code, I try to test with buttons and linearlayout. I do this because in my real

Selector doesn't work with click button effect

Roger_88: I want to change the background color of itemviewholder when it is clicked. For this I tried using "selector" and "state_pressed" on it but it doesn't work. In this test code, I try to test with buttons and linearlayout. I do this because in my real

Selector doesn't work with click button effect

Roger_88: I want to change the background color of itemviewholder when it is clicked. For this I tried using "selector" and "state_pressed" on it but it doesn't work. In this test code, I try to test with buttons and linearlayout. I do this because in my real

Selector doesn't work with click button effect

Roger_88: I want to change the background color of itemviewholder when it is clicked. For this I tried using "selector" and "state_pressed" on it but it doesn't work. In this test code, I try to test with buttons and linearlayout. I do this because in my real

jQuery .on Event doesn't work with variable selector

Arthur Tarasov I need to create Click functionality for dynamically loaded elements . The ID of the element is in a variable $element. The ID stores a string. I pass it to the .onevent handler like this: ... .on("click", '"'+$element+'"', function() { ... It

jQuery .on Event doesn't work with variable selector

Arthur Tarasov I need to create Click functionality for dynamically loaded elements . The ID of the element is in a variable $element. The ID stores a string. I pass it to the .onevent handler like this: ... .on("click", '"'+$element+'"', function() { ... It

click event click doesn't work

Alifur Islam History and homepage are working fine but 'ng-click="toggleMenu()"' is not working so please help me click event is ng-click="toggleMenu()"not working. Can someone help me out? my code is <ion-tab title="History" icon-off="ion-document" icon-on="i

click event click doesn't work

Alifur Islam History and homepage are working fine but 'ng-click="toggleMenu()"' is not working so please help me click event is ng-click="toggleMenu()"not working. Can someone help me out? my code is <ion-tab title="History" icon-off="ion-document" icon-on="i

click event click doesn't work

Alifur Islam History and homepage are working fine but 'ng-click="toggleMenu()"' is not working so please help me click event is ng-click="toggleMenu()"not working. Can someone help me out? my code is <ion-tab title="History" icon-off="ion-document" icon-on="i

jQuery click event doesn't seem to work

Akahne Saikyo I'm practicing making a simple calculator using jQuery, and I think the code itself is pretty simple, but no matter what I do, absolutely nothing happens, as if there's no js file linked to beging. Here is the jQuery code: function ud(n){

jQuery .off("click") event doesn't work

basic need help This has been bugging me for hours and still confused as to why it doesn't work... When I use table.off("click");it , it also unbinds the click event of the first child without id=multi. var table = $("table#datatable") var button = $(".generat

FloatingActionButton Click event doesn't work

George I have a floating action button in the following layout file activity_register: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"

Knockout click event doesn't work

Mike Wells I'm creating a weather page for myself (and possibly others in the future) and am having trouble with the button to show and hide weather alerts. You can check the page to see what I'm trying to do. (Sorry, I'm picking FL, but they have a lot of ale

Click event doesn't work in javascript

Soheil Alizadeh I will follow this article on Impredement CRUD operations with HTML5 and Javascript . This allows the data to be committed to local storage and saved. My problem is that there is no "delete and edit action" when clicking the "delete and edit" b

click event on options doesn't work in Safari

Large size I will recreate my problem with a very simple code (see below): <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> </head> <body> <select class="a"> <option class="b" value="opt1">o

Onclick event doesn't work on first click

Vihar After the page loads, I need to click the button twice to trigger the onclick()function. After doing this, everything works as expected. Since I'm new to this web development field, I'd really appreciate a detailed explanation. Thank you in advance. var

jQuery click event doesn't work

mightyspaj3 I have this simple jQuery click event and for some reason it's not working. works, I can use this inside the $(document).ready(function() {});alert; however the actual click event doesn't work. Thanks in advance and please take it easy on me as I d

MathJax doesn't work in Jquery .click event

Glagas Incoming MathJaxJquery .clickevent doesn't work inside but outside that function. Run the code snippet to see the effect. $('#math').click(function(e){ e.preventDefault(); $("#result").html("$$ MathJax inside .click event doesn't work $$"); }); //outsid

jQuery Click event doesn't work on mobile

lkw3274 I'm trying to make the following JSFiddle work for tablet/mobile (eg "touch" and "click"). https://jsfiddle.net/lkw274/7zt1zL0g/87/ <div class="user-navigation"> <a class="mobile-menu-new" href=""><span></span>Menu</a> </div> $(document).ready

Click event doesn't work on dcmads

Germet Singh | I want to make an ajax call whenever someone clicks on a dcmads ad placed on my site. But I can't do it. I thought it was somehow because of event bubbling and catching, even trying to resolve it, but that didn't have any effect. HTML - <div cla

$(this) doesn't work in defined click event

Pawan Yekabot $(document).ready(() => { $(".tabs-item").click(() => { $(".tabs-item").removeClass("active"); $(this).addClass("active"); //This line is not at all working.. }); }); $(this)doesn't work at all. I've been trying different appro

"this" doesn't work in click event handler

network I have attached a click event handler to my ChartJS derived component like this: export default { extends: HorizontalBar, data() { return { my_data: [], options: { onClick: function(event, args) { //need to access