0

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.

Ryan King
  • 3,538
  • 12
  • 48
  • 72

2 Answers2

2

Maybe you can use HTML

     $('<div />', {'class': 'preview'}).html('<p>Test</p>').insertAfter($uls.eq(0));
youssDev
  • 90
  • 4
1

try using html instead of text, something like this :

$('<div />', {'class': 'preview', html: '<p>Test</p>'})
andri
  • 1,021
  • 1
  • 9
  • 16