Utkarsh Bhatt
Utkarsh Bhatt

Reputation: 1606

How to select a nested element in a table with jquery with no ID and classes

I have this table with an element nested as follows:

table > tbody > tr > td > table > tbody > tr > td > a

None of the elements have an ID or a class.

Upvotes: 0

Views: 439

Answers (1)

Death-is-the-real-truth
Death-is-the-real-truth

Reputation: 72299

You can pass the same in jQuery as selector:-

$('table > tbody > tr > td > table > tbody > tr > td > a').on('click',function(){
  // do stuff
});

Working sample Example:-

$('table > tbody > tr > td > table > tbody > tr > td > a').on('click',function(){
 alert($(this).attr('id'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
  <tbody>
    <tr>
      <td>
        <table>
          <tbody>
            <tr>
              <td>
                <a id="my_id">Click Me To Get my Id!</a>
              </td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
  </tbody>
</table>

Upvotes: 3

Related Questions