Search code examples
jqueryasp.netradiobuttonlist

how to get dynamically created radibuttonlist's count with jquery


How do you get the count of dynamically created Asp.Net Radiobuttonlist's count ?

here is my radiobuttonlist

<asp:RadioButtonList ID="rbl_poll" runat="server"></asp:RadioButtonList>

I tried this but didnt work

if ($("#<%=rbl_poll.clientId %>").length == 0) {
   $("#div_poll_box").hide();
}

Solution

  • The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document).

    You can use class(class="rbl_poll") insread of id(ID="rbl_poll")

    <asp:RadioButtonList class="rbl_poll" runat="server"></asp:RadioButtonList>
    

    And change script

    if ($(".rbl_poll").length == 0) {
       $("#div_poll_box").hide();
    }