How to create parent element?

Asked

Viewed 116 times

3

How to create a parent tag within an element with jQuery, for example, having this original structure:

<p>texto</p>

After function jQuery would look like this:

<a href='#'>
    <p>texto</p>
</a>

1 answer

5


You can do it like this:

$('p').wrapAll('<a href="#" />');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<p>texto</p>

  • Show man, thank you so much!

  • You’re welcome @Talesbreno

Browser other questions tagged

You are not signed in. Login or sign up in order to post.