Question

I had someone help me out earlier and they used this notation to insert a paragraph with jQuery. I haven't seen it before.

$('<p />', {'class': 'preview',text: 'Test'}).insertAfter($uls.eq(0));

Inserts:

<p class="preview">Test</p>

How do I modify this code to insert the following instead?

<div class="preview"><p>Test</p></div>

I've tried: $('<div />', {'class': 'preview',text: '<p>Test</p>'}) But it parses the <p> tags as text.

Était-ce utile?

La solution 2

try using html instead of text, something like this :

$('<div />', {'class': 'preview', html: '<p>Test</p>'})

Autres conseils

Maybe you can use HTML

     $('<div />', {'class': 'preview'}).html('<p>Test</p>').insertAfter($uls.eq(0));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top