0

I want to add a <span> element inside <label> with jQuery:

jQuery('.custom-checkbox2 label').wrapInner('<span class="circle"></span>');

This is a default state:

<div class="custom-checkbox2">
    <input type="checkbox" id="chcb">
    <label for="chcb">Text</label>
</div>

This is what I want:

<div class="custom-checkbox2">
    <input type="checkbox" id="chcb">
    <label for="chcb">
        <span class="circle"></span>Text
    </label>
</div>

And this result I'm getting:

<div class="custom-checkbox2">
    <input type="checkbox" id="chcb">
    <label for="chcb">
        <span class="circle">Text</span>
    </label>
</div>

1 Answer 1

1

The function you are looking for: prepend()

So in your case instead of .wrapInner('<span class="circle"></span>') You use .prepend('<span class="circle"></span>')

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.