TriSTaR TriSTaR - 23 days ago 7
Javascript Question

jQuery addClass over html Tags

I want to

addClass
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>
</div>


UPD Thank you all )

Answer

$('h4,p').wrapAll("<div class=myClass></div>")
.myClass {
  color: red
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></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.