Insert something .after a set of elements if the first in the set has a certain class.

Posted by Adripants on Stack Overflow See other posts from Stack Overflow or by Adripants
Published on 2011-01-13T01:38:07Z Indexed on 2011/01/13 1:53 UTC
Read the original article Hit count: 191

Filed under:

I would like to add a label AFTER a group of radio inputs IF the first has a certain class

<label>Has the strategy and all of it's relevant background documents been uploaded</label>

<label for="Radio1"><input type="radio" name="uploaded" class="required cat1" id="Radio1">Yes</label>

<label for="Radio2"><input type="radio" name="uploaded" id="Radio2">No</label>

Radio1 has the class, but I'd like to insert a label after the last (in this case Radio2)

I thought I could use this:

$('input[type="radio"].cat1').siblings('input:last').after('<label>Hi!</label>');

But it doesn't work. Can you pick what I am doing wrong?

© Stack Overflow or respective owner

Related posts about jQuery