Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html is rendered event

I'm appending some code to my page using jQuery AJAX calls. This code is a mix of html and javascript. But I want javascript to be executed only when html part is ready. But what event is raised when appended html is rendered?

Here is an example:

<table id="sampleTable">
   ...
</table>

<script>
  // this code should be executed only when sampleTable is rendered
  $('#sampleTable').hide();
</script>
like image 219
SiberianGuy Avatar asked Dec 29 '22 21:12

SiberianGuy


1 Answers

Use the jQuery ready() event:

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

<edit> It seems to be impossible to call a ready event on any other object than Document, my bad </edit>

This is an option if you are talking about the event triggered after a successful Ajax request :

$('#sampleTable').ajaxComplete(function() {
    $(this).hide();
});

Or just hardcode the style of the table to display:none;...

like image 100
Powertieke Avatar answered Jan 10 '23 22:01

Powertieke