javascript - How to set the first child element's radio_button checked in rails4? -


i using rails4. have dropdown of list. want check radio_button of first child element. items in dropdown list parent , on selection of each parent list shown children.all child elements displayed via loop, of javascript, displaying child elements belongs selected parent dropdown.

template onchanging parent_id, " $("select[id='parent_<%=@parent.id%>']").change" called child element in template are:-

<div class="child<%= @parent.id %>" style="display:none">                <%=radio_button :child_name, @parent.id, child.name ,id: "child"%><%=child.name%>  </div>  $("select[id='parent_<%=@parent.id%>']").change(function(){      $(".child"+ this.value).each(function(){         $(this).show();         $(this).firstelementchild.setattribute("checked","checked"); //its not working      });  }); 

try this:

// instead // $(this).firstelementchild.setattribute("checked","checked");  $(this).children().first().attr("checked", true); 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -