<...">

Get td tr click class?

How can I get the td class from clicking tr?

I have this structure:

<tr role="row" data-id="1" class="odd parent">
   <td class="sorting_1">test</td>
   <td>foo</td>
   <td>3223232</td>
</tr>

I wrote this code:

$('#datatable > tbody > tr').click(function()

what I want to do is to prevent the processing of the above code if the user clicks on tdwith the class sorting_1. Each tr has td with this class, so I need to check if the user clicked this td class and prevent code from executing.

UPDATE

The code provided by @TJ Crowder works well, but when I click on <td>which has this class, I cannot continue the code, that’s right. But I need to check if td contains ::before, infact this will be added when html does not have enough space (responsive), in this case the correct structure:

<tr role="row" class="odd parent" data-id="1">
    <td class="sorting_1">test</td>
       ::before
       "test"
    <td>foo</td>
    <td>3223232</td>
</tr>
+4
1

, td :

$('#datatable > tbody > tr').on("click", "td:not(.sorting_1)", function(e) (
// -------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    // ...
});

( , , td.)


, target , :

$('#datatable > tbody > tr').click(function(e) (
    // -------------------------------------^
    if ($(e.target).hasClass("sorting_1")) {
        // Don't do it
        return;
    }
});

td (span, em ..), closest, :

$('#datatable > tbody > tr').click(function(e) (
    // -------------------------------------^
    if ($(e.target).closest(".sorting_1").length) {
        // Don't do it
        return;
    }
});

:

, td :before? ' :before, html (). , , td, , :before, , . : td?

getComputedStyle :

console.log(
  getComputedStyle($("#target")[0], "::before").content
);
#target::before {
  content: 'Life, the Universe, and Everything? '
}
<div id="target">42</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Hide result

, , getComputedStyle. , :before ( ) ::before ( ).

+4

Source: https://habr.com/ru/post/1651925/


All Articles