开发者

Load HTML in place with jQuery

开发者 https://www.devze.com 2023-02-13 18:41 出处:网络
I need to load a piece of HTML from a list of HTML inserts $(\'#placeholder1\').html($(\'.html3\').html());

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(){});

0

精彩评论

暂无评论...
验证码 换一张
取 消