Oz Bar-Shalom Oz Bar-Shalom - 3 years ago 142
HTML Question

jQuery - element.on click for match cases

I have an element that is inside a table somewhere.
I need to get his tbody element.

How can I do that?



But it looks like it did not work..

My code:

$("table").on('click', ['td'], function(event) {

if ($(this).hasClass('uneditable')) { return; }
// here I need to check the tbody element

Maybe I am doing this wrong, because I want to apply this function only if a click on a table with specific classes for elements:

  • table -

  • tbody -

  • td - not

Thanks !

Answer Source

So just bind click to the tbody that has the class and check the class on click.

$("table.dattable tbody.editable").on("click", "td:not(.uneditable)", function(){});

Or id the .editable is dynamic on the table than move it to the other selector

$("table.dattable").on("click", "tbody.editable td:not(.uneditable)", function(){});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download