Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide an element in the tables first row

Tags:

html

jquery

css

I have the following table

<table id="mytable">
  <tr>
     <td>name</td>
     <td>
       <a id="button1" class="button">link</a>
     </td>
  </tr>
  <tr>
     <td>name2</td>
     <td>
       <a id="button2" class="button">link</a>
     </td>
  </tr>
</table>

I want to hide the first row first column button using jQuery, but I'm not sure how to do that, but I was manage to do the following (to make the first tr font italic).

$(document).ready(function() {
  $("#mytable tr:first").css("font-style", "italic");
});
like image 464
sameera207 Avatar asked Dec 21 '22 11:12

sameera207


2 Answers

As you have id of button, you can use id to hide it.

$('#button1').hide();

If you want to use class and can not using id for some reason, you can use find() method to find the element within descendants fulfilling given selector criteria.

Live Demo

$(document).ready(function() {
  $("#mytable tr:first").find('.button').hide();
}); 
like image 56
Adil Avatar answered Jan 02 '23 13:01

Adil


use this code

    <script>
        $(document).ready(function() {
      $("#mytable tr:first #button1").css("display", "none");
    });
    </script>
like image 24
Manish Nagar Avatar answered Jan 02 '23 13:01

Manish Nagar