0

So I have this html markup:

<div class="buttons-holder>
    <label class="my-btn">
        <input name="example" value="1" type="radio"> YES
    </label>
    <label class="my-btn">
        <input name="example" value="0" checked="checked" type="radio"> NO
    </label>
</div>  

But sometimes I have more than one label inside the .buttons-holder element. How can I specify in jQuery to apply my jQuery code only if there exists 2 label elements?

I tried something like this but it still applies to all elements:

    if ($('form label:has(input[type="radio"])').eq(2)) { 
        //do something 
    } else {
        //do something else
    }

Jsfiddle: http://jsfiddle.net/jw51hggc/

Xenyal
  • 2,136
  • 2
  • 24
  • 51
Eddi
  • 85
  • 1
  • 14

1 Answers1

2

Based on your comments and fiddle

$('form .buttons-holder').filter(function(){
    return $(this).children('label:has(input[type="radio"])').length == 2
}).wrapInner('<div class="wrap"></div>');

Demo: Fiddle

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531