سؤال

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