开发者

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

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?


You could try this:

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

So find the radio button with required class, go to its parent (label) then the parent of that (whatever your container is) then find the last label and append a label after it.

Edit: didnt notice your inputs were nested in a label. have fixed for that. Also you may need to tweak selectors a bit depending on your requirements.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜