javascriptjqueryjquery-uijquery-ui-button

Get nth button in a jquery-ui buttonset


Is there some way to get the nth button in a jquery-ui buttonset?

$( "#radio" ).buttonset();
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<div id="radio">
      <input type="radio" id="sizzle" name="project">
      <label for="sizzle">Sizzle</label>
 
      <input type="radio" id="qunit" name="project" checked="checked">
      <label for="qunit">QUnit</label>
 
      <input type="radio" id="color" name="project">
      <label for="color">Color</label>
</div>

I can select button qunit using its id selector.

But is there any way to select say the 2nd button in this set?


Solution

  • There are multiple ways you can select it in jQuery

    $("#radio input[type=radio]").eq(1)
    

    OR

    $("#radio input[type=radio]").get(1)
    

    OR

    $("#radio input[type=radio]:eq(1)")