How can i ignore a click on a selected column

How can i ignore a click on a selected column

gman0104gman0104 Posts: 7Questions: 3Answers: 0

I have four columns in my table and i want to ignore the click on column 4. How can i achieve this via JavaScript

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    Something like this td:not(:nth-child(4)). If this doesn't help please provide more details of what you are doing/. Maybe a code snippet of your event handler selector.

    Kevin

  • gman0104gman0104 Posts: 7Questions: 3Answers: 0

    Hi my code is as follows

    $('#myTable tbody').on('click', 'tr', function () {
          setDate(value);
    } );
    
  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Yep, do what Kevin said above - replace tr with his suggestion.

    Colin

  • gman0104gman0104 Posts: 7Questions: 3Answers: 0

    Sorry i forgot to include a line but if i update the code as follows im not getting a value for var value=$(this).find('td:first').html();

    $('#myTable tbody').on('click', 'td:not(:nth-child(4))', function () {
    var value=$(this).find('td:first').html();
    setDate(value);
    } );

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954
    Answer ✓

    Maybe something like this will work?

    $('#myTable tbody').on('click', 'td:not(:nth-child(4))', function () {
      var tr = $(this).closest('tr');
      var value=$( tr ).find('td:first').html();
      setDate(value);
    } );
    

    Kevin

  • gman0104gman0104 Posts: 7Questions: 3Answers: 0

    Fab this has sorted my issue thanks kthorngren and Colin

This discussion has been closed.