John Doe
John Doe

Reputation: 2924

jQuery hide function not working properly

Here is my PHP code. In this I am creating a table and Populating data by pulling it from the database. I am printing two rows. In the second table row I have written "Hello There". My understanding of .hide() function makes me belief that it should be hidden on page display. But its not happening so?

<table>
    <thead>
        <tr>
            <th>All Courses</th>
            <th>Center</th>
            <th>Batch</th>
            <th>Click for Info</th>
        </tr>
    </thead>
    <tbody>
              <?php 
                if($batch_query != null){
                  $i = 0;  
                  foreach($batch_query->result_array() as $row){
                    $val = "'".$row['course_id'].",".$row['center_id'].",".$row['batch_id']."'";
                    echo "<tr>";
                      echo "<td>".$row['course_name']."</td>";
                      echo "<td>"."<button id= \"btn_number_$i\"  class='btn info toggler' >Info   <i class='icon-arrow-down'></i></button>"."</td>";
                    echo "</tr>";
                    echo "<tr class='info_row'>Hello There!!</tr>";
                    $i++;
                  }
               }

In the code I am creating two rows and initially I want to set the display property of second row to none by using jQuery hide method.

Here is my jQuery code in between the script tag on the same page:

   $(function(){
    console.log('Hello World!!');// Just to test whether the code is being reached or not.  
    $('.info_row').hide();  
   });

But this hide() function does not seem to be working. The whole string "Hello there" remains on the page.

What could be the reason for this ?

Upvotes: 0

Views: 55

Answers (2)

bipen
bipen

Reputation: 36531

your html is invalid..missed <td> within <tr>

it should be

 echo "<tr class='info_row'><td>Hello There!!</td></tr>";
                         //--^^-here 

Upvotes: 1

PSR
PSR

Reputation: 40318

try this

$(".tableClass table tr").eq(1).hide();

you need to have <td> in <tr>

Upvotes: 1

Related Questions