Load HTML in place with jQuery
I need to load a piece of HTML from a list of HTML inserts
$('#placeholder1').html($('.html3').html());
<td id="placeholder1">
// place html here
</td>
<div style="display:hidden">
<div class="html1">
// some HTML 1 here
</div>
<div class="html2"&开发者_Python百科gt;
// some HTML 2 here
</div>
<div class="html3">
// some HTML 3 here
</div>
</div>
Does not seem to work. What am I missing? Thanks.
Place the jquery code after the html is rendered.
or use this like
// Doing this wait for js to run until the DOM is loaded
$(document).ready(function() {
$('#placeholder1').html($('.html3').html());
});
Try wrapping your jQuery code in a ready
block.
$(function(){
$('#placeholder1').html($('.html3').html());
});
Note: $(function(){});
is a shortcut for $(document).ready(function(){});
精彩评论