Event Click, take the value of line input dynamically

Asked

Viewed 32 times

-2

I have the following code below

<body>
   <table>
  <tr>
    <th>Company</th>
    <th>Contact</th>
    <th>Country</th>
  </tr>
  <tr class='item'>
    <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>Germany</td>
    <input type="hidden" value="0">
  </tr>
  <tr class='item'>
    <td>Centro comercial Moctezuma</td>
    <td>Francisco Chang</td>
    <td>Mexico</td>
    <input type="hidden" value="1">
  </tr>
</table>
  </body>
<Script> 
   $(document).on('click', '.item', function(){
    console.log(this);
    $(this).remove();   
   });
</script>

I want to take the value of the invisible input or even some particular column. The click event I made I can get all the element TR and child elements, however I can not access a data in specific by This. Someone can help me, if I can get the value of the input that comes in This?

1 answer

0

<Script> 
$(document).on('click', '.item', function(){
 console.log($(this).children('input[type=hidden]')[0].attributes.value); 
});

the Children('input')[0] command will search for the first input with type Hidden and Attributes.value will select the value attribute hope I’ve helped

  • 1

    I can also filter by which other ne tag?

  • of course. You just need to change the tag and the input selector. If you want you can even choose more than one tag by separating by comma within the tag, for example 'input, div'. I recommend you research more about selectors in jquery

Browser other questions tagged

You are not signed in. Login or sign up in order to post.