user3119163
user3119163

Reputation:

Facing issues while hiding div

i am creating a table and hide it immediately after its creation. [don't want to face DOM]. then user select from dropdown and i show it. its working fine. but when i go to that page for the first time it does not hide that div.

code

<table class="table table-striped table-bordered " id="book_info" >
    <tbody>
    <tr>
    <td>
    ...
    </td>  
    </tr>
   </tbody>
  </table>
  <script> $('#book_info').hide();
            alert("passed");
  </script>
    <!-- remaining html stuff-->

that alert do not hit when i goto that page. when i refresh the page ,it shows alert...

Upvotes: 0

Views: 41

Answers (1)

James Donnelly
James Donnelly

Reputation: 128856

You need to wrap your jQuery method calls in a document ready():

$(document).ready(function() {
    $('#book_info').hide();
    ...
});

Alternatively you could just use CSS to initially render the table hidden:

#book_info {
    display: none;
}

...then call jQuery's show() method when you want to display it:

$('#book_info').show();

Upvotes: 2

Related Questions