Nina
Nina

Reputation: 130

insert <span> tag in an existing <p> tag with content in jquery

I have this html element

<p>The content</p>

I would like to add a span around the existing text with jquery

<p><span>The content</span></p>

Is there a way to do this ?

Upvotes: 1

Views: 443

Answers (1)

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

You have to use .wrapInner at this context,

$("p").wrapInner("<span>");

This will wrap the content of paragraph by a span element.

DEMO

Upvotes: 1

Related Questions