Will
Will

Reputation: 1164

adding options to dropdownlist using jquery

Im new to jquery, and what im trying to do is add new option to a dropdownlist. Here what I have so far. Could somone explain what im doing wrong?

   <asp:DropDownList ID="drop_company" runat="server"/>

     These dont work:
    $("#drop_company").append($("<option>").val("this"));
    or
    $("#drop_company").append($("<option value="1">Apple</option>"));

Upvotes: 0

Views: 74

Answers (1)

Selvakumar Arumugam
Selvakumar Arumugam

Reputation: 79830

Try,

$("#drop_company").append('<option value="1">Apple</option>');

  1. You were missing $ in ("#drop_company")
  2. You can append it a simple string
  3. You cannot use double quotes inside double quotes without escaping it, else you can use a single quote and inside which you can use double quotes like above.

Upvotes: 1

Related Questions