how to get next relative dropdown using jquery

i have this code

<div id="aggregate" style="display:inline">
                    <%=Html.RadioButton("a", "1", true, new {id = "meRadio"})%><label>Me</label>
                    <%=Html.RadioButton("a", "2", false, new { id = "teamRadio" })%><label>Team: </label><% = Html.DropDownList("Teams", Model.Teams,  new {@scope="Team",  @id = "teamDropdown", @class = "filterDropdown" })%>
                    <%=Html.RadioButton("a", "4", false, new { id = "managerRadio" })%><label>Manager: </label><% = Html.DropDownList("Managers", Model.People, new { @scope = "Manager", @id = "managerDropdown", @class = "filterDropdown" })%>
                    <%=Html.RadioButton("a", "5", false, new { id = "locationRadio" })%><label>Location: </label><% = Html.DropDownList("Locations", Model.Locations, new { @scope = "Location", @id = "locationDropdown", @class = "filterDropdown" })%>
  </div>

i currently have code like this:

 $('#workstreamRadio').click(function () {
     Enable("#workstreamDropdown");
 });

 $('#teamRadio').click(function () {
     Enable("#teamDropdown");
 });

I am sure there is a way using jquery to dynamically get the respective dropdown selector given a specific radio button clicked so i dont have to hard code each mapping.

what is the syntax for saying "get me the selector of the dropdown to the right of the radio button i clicked"

1
задан Nick Craver 29 August 2010 в 12:50
поделиться

1 ответ

Вы можете сделать это, используя .nextAll() и :first следующим образом:

$("#aggregate :radio").change(function() {
  var dropdown = $(this).nextAll("select:first");
  //enable or disable dropdown
});

поскольку они братья и сестры, используйте .nextAll() , который проходит через всех братьев и сестер, и вам нужен первый элемент