How to get the value of an input inside a td in jquery

1

Hello, I have the following table in html

<table style="display:none;" id="tableTime">  
        <tr>
            <td class="hora">08:00</td>
            <td class="eventoAgenda" id="0800"></td>
            <td class="idEvento" id="id0800"></td>
            <td class="statusVerde"> <input name="status" type="checkbox" ></input> </td>
        </tr> 

How do I get the <input> that is inside the <td class="statusVerde> in jquery ??

I tried something similar to this:

$('#tableTime tr #statusVerde input #status')

But obviously it did not work out

    
asked by anonymous 18.01.2016 / 18:48

2 answers

2

Add id="status" to input . See it working:

$(document).ready(function() {
  var a = $('#status').val();
  alert(a);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><tablestyle="display:none;" id="tableTime">
  <tr>
    <td class="hora">08:00</td>
    <td class="eventoAgenda" id="0800"></td>
    <td class="idEvento" id="id0800"></td>
    <td class="statusVerde">
      <input name="status" id="status" type="checkbox" value="teste"></input>
    </td>
  </tr>

Or by the name attribute:

$(document).ready(function() {
  var a = $('input[name="status"]').val();
  alert(a);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script><tablestyle="display:none;" id="tableTime">
  <tr>
    <td class="hora">08:00</td>
    <td class="eventoAgenda" id="0800"></td>
    <td class="idEvento" id="id0800"></td>
    <td class="statusVerde">
      <input name="status" type="checkbox" value="teste"></input>
    </td>
  </tr>

Reference:

How to set value of input text using jQuery

    
18.01.2016 / 18:56
1

You need to initialize an attribute to your input for example <input name="status" id="statusAqui" type="checkbox"> after that select it with jQuery $('#statusAqui') .

    
18.01.2016 / 19:03