TriSTaR TriSTaR - 9 months ago 68
Javascript Question

jQuery addClass over html Tags

I want to

over tags with jQuery...

For example: I have this

<h4>Any title</h4>
<p> Text intro </p>

I wanna add the Class over it's..

<div class="myClass">
<h4>Any title</h4>
<p> Text intro </p>

UPD Thank you all )

Answer Source

$('h4,p').wrapAll("<div class=myClass></div>")
.myClass {
  color: red
<script src=""></script>
<h4>Any title</h4>
<p>Text intro</p>

Use .wrapAll()

Description: Wrap an HTML structure around all elements in the set of matched elements.