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.

Was it helpful?

Solution 2

try using html instead of text, something like this :

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

OTHER TIPS

Maybe you can use HTML

     $('<div />', {'class': 'preview'}).html('<p>Test</p>').insertAfter($uls.eq(0));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top