Home > Software design >  How to wrap a button's text/value in a span?
How to wrap a button's text/value in a span?

Time:11-14

Very simple issue. I need to wrap the button's text (Buy Now) in a span. Can anyone suggest how I might do that using jQuery?

<button type="submit" name="add-to-cart" value="22706" class="single_add_to_cart_button button alt">Buy Now</button>

CodePudding user response:

$( '.button' ).wrapInner( "<span class='test'></span>");

CodePudding user response:

You can replace any HTML markup by using jQuery's .replaceWith() method.

If you want to keep the existing markup, you could use code like this:

$('.single_add_to_cart_button').replaceWith('<span>'   $('.single_add_to_cart_button').html()  '</span>')
  • Related