Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to have an onClick event fire for certain radio button children of a <tr>

I have a table row inside of a table. Inside this table row I have 4 buttons. I want to use jquery to fire an onClick for any button in the row except for the 1st one. Is there an easy way to select the <tr> itself instead of recreating an onClick for every button?

<table class="table table-striped stickeyHeaders">
    <tr id="buttonRow">
        <td><input type="radio" name="SelectedStoreRoles" class="store-privs" value="1"/>     
        <td><input type="radio" name="SelectedStoreRoles" class="store-privs" value="2"/>     
        <td><input type="radio" name="SelectedStoreRoles" class="store-privs" value="3"/>     
        <td><input type="radio" name="SelectedStoreRoles" class="store-privs" value="4"/>     
    </tr>
</table>

Here is my general though process but need some help to flesh it out all the way

$('#buttonRow').children("Some Filter that says value > 1").On('Click, function({}));

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use the :gt selector to avoid the first element:

$('#buttonRow').find(":radio:gt(0)").on('click', e => {
  console.log(e.target.value);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<table class="table table-striped stickeyHeaders">
  <tr id="buttonRow">
    <td><input type="radio" name="SelectedStoreRoles" class="store-privs" value="1" /></td>
    <td><input type="radio" name="SelectedStoreRoles" class="store-privs" value="2" /></td>
    <td><input type="radio" name="SelectedStoreRoles" class="store-privs" value="3" /></td>
    <td><input type="radio" name="SelectedStoreRoles" class="store-privs" value="4" /></td>
  </tr>
</table>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading