Putri Arisnawati
Putri Arisnawati

Reputation: 53

How to replace tags with jquery?

I have a question, I want to replace the following code

<h2> Heading 1</h2>
<h2> Heading 2</h2>

with the following code

<h2><span> Heading 1</span></h2>
<h2><span> Heading 2</span></h2>

I want to do that with jquery. Please help me...

Upvotes: 0

Views: 98

Answers (4)

Selvakumar Arumugam
Selvakumar Arumugam

Reputation: 79830

Try using wrapInner.

$('h2').wrapInner('<span/>')

Upvotes: 6

Prasenjit Kumar Nag
Prasenjit Kumar Nag

Reputation: 13461

You can do this using $.wrapInner

$('h2').wrapInner('<span/>')

Upvotes: 0

zzzzBov
zzzzBov

Reputation: 179046

Please take some time to review the jQuery api. wrapInner will do the trick.

$('h2').wrapInner('<span>');

Upvotes: 2

Fabrizio Calderan
Fabrizio Calderan

Reputation: 123387

Just use

$('h2').wrapInner('<span/>')

Upvotes: 1

Related Questions