views:

18

answers:

1

So I have something like

<div>
  <!-- other stuff then-->
  <button>Hey</button>
</div>

and I'd like to make that (using Javascript/JQuery)

<div>
  <!-- other stuff then-->
  <div class="bw">
    <button>Hey</button>
  </div>
</div>

Is that possible? I couldn't find anything with material on it online…but, I'm a totally JS noob, so I'm probably not using the right terminology. Thanks!

+4  A: 

You can use .wrap() for this:

$("button").wrap("<div class='bw'></div>");

You can test it here, for wrapping multiple elements, use .wrapAll(), here's a full list of the wrapping functions.

Nick Craver