0

I have two big blocks of HTML on one page, they are exactly the same but I need them in two places. Is there a method that allows me to delete one block and "call/load" the other block instead. Therefore reduce my page size/speed and update admin. I know there is a jquery snippet that calls/loads another html page and places the content in the id (below) but can this be done with content on the same page?

            $(document).ready(function () {
                $("#div").load('page.html');
                });
4

1 回答 1

1

是的,你可以使用

var new_div = $('#div').clone();

然后使用 append/prepend/insertBefore 等将其插入 DOM。

确保更改克隆的 id,否则插入克隆后 DOM 操作可能会出现复杂情况。

于 2013-08-08T14:16:03.700 回答