4

I have these elements:

<div class="qtip-error">...</div>
<div class="qtip-error">...</div>
<div class="qtip-error">...</div>

and

<span class="validation-error">...</span>
<span class="validation-error">...</span>
<span class="validation-error">...</span>

What is the best way to assign each span to the corresponding div based on the index? I've been looking at somehow implementing .each() but I'm not sure how to make it work right. If there is a better approach, I am open to suggestions, but please, no plugins.

Thanks!

0

1 Answer 1

4
var qtips = $('.qtip-error');
$('.validation-error').each(function (i) {
   qtips.eq(i).after(this);
});

See demo: http://jsfiddle.net/zR9bL/.

Instead of after(this) you can use append(this) if you want the <span> to be within the <div>.

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.