I have some problem with jQuery. When am trying use:

document.querySelector('#container').appendChild(content.cloneNode(true));

it's ok, but jquery have wrapper around the object, so i can't just type:

$('#container').content

Does anyone have any ideas?

有帮助吗?

解决方案 2

If you want to access the actual DOM element for a single-element selection, use $('#container')[0] or $('#container').get(0).

If you had multiple elements in your selection, you could get them by index: .get(1), .get(2) and so on.

其他提示

The HTML5 provides a template element:

contents = $('#template').html();
copy = $('<div id="copy"></div>');
$('body').append(copy.append(contents));

The HTML part:

<html>
  <body>
    <template id='template'>
    </template>
  </body>
</html>

The clone method is not sufficient.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top