[RESOLVED]How do I remove an item form a listbox using its index with jquery

How do I remove an item from an asp.net ListBox using its index and JQuery?

After u have the jquery plugin

please refer this url 

http://www.craiglotter.co.za/2010/02/27/remove-all-listbox-and-dropdown-list-items-with-jquery/

I didn’t see where it showed how to remove an item using its index.  can you point me to it?

Try this 

#("listId").eq(1).remove();  // pass index in .eq

Check the sample application I’ve created for you

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ForumsTest.WebForm1" %>

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript"
        src="http://code.jquery.com/jquery-latest.min.js" charset="utf-8">
    </script>
    <script type="text/javascript">
        $(function () {
            $("option:eq(2)").remove(); //this will remove the third option
        })
    </script>
</head>
<body>
    <form runat="server">
        <asp:ListBox ID="ListBox1" runat="server">
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            <asp:ListItem>3</asp:ListItem>
        </asp:ListBox>
    </form>
</body>
</html>

I’m using jQuery :eq() selector.

Thanks!

Leave a Reply