Wrap Divs with the same class

Asked

Viewed 24 times

1

I want to apply the insertion of labels with Javascript or jQuery.

I have this code:

<div class="name">...</div>
<div class="name">...</div>
<div class="name">...</div>
<div class="name">...</div>
<div class="name">...</div>

And I’d like it to stay that way:

    <label>
    <div class="name">...</div>
    </label>
    <label>
    <div class="name">...</div>
    </label>
    <label>
    <div class="name">...</div>
    </label>
    <label>
    <div class="name">...</div>
    </label>
    <label>
    <div class="name">...</div>
    </label>

Remembering that these divs are being written by a Javascript function (in this function is being used a for) with different content but with the same functionality so they have the same class.

1 answer

1


With jQuery you can use .wrap():

$(".name").wrap("<label />");

Upshot:

inserir a descrição da imagem aqui

  • Thank you very much solved my problem ;)

Browser other questions tagged

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