replacewith - jquery add tag after another tag -



replacewith - jquery add tag after another tag -

i have following:

<h3>my title</h3>

and add together following:

<h3><span>my title</span></h3>

i have tried accomplish following:

$( "<h3>" ).replacewith( "<h3><span>" ); $( "</h3>" ).replacewith( "</span></h3>" );

but above doesn't seem working. approaching in right way?

you can't replace element string.

in case can utilize .wrapinner()

class="snippet-code-js lang-js prettyprint-override">$('button').click(function() { $('h3').wrapinner('<span />'); }) class="snippet-code-css lang-css prettyprint-override">h3 span { color: red; } class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <h3>my title</h3> <button>wrap</button>

jquery replacewith

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -