jQuery Get Selected Index Examples – 2 Ways

At times, it could be very useful to use jQuery to Get Selected Option Index value for carrying out relevant processing. In this article, I am going to show you a very easy and simple way to get selected option index value using jQuery. And the actual code is just 1 line, so it’s super easy to follow and implement.

Examples to Get Selected Option Index using jQuery

Let’s assume that you have a select dropdown with ID “countries”. To get the index of the selected option, you can use any of the following 2 methods:

Method 1: By using the ‘ID’ of the select dropdown:

Method 2: By using the ‘name’ of the select dropdown:

Example: Get Selected Option Index using jQuery

Very simple, isn’t it?

Do you know of any other ways to use jQuery to get selected index / get selected option index ? Feel free to suggest by commenting below.

3 Comments on jQuery Get Selected Index Examples – 2 Ways

  1. 1

    It is not working for me.
    alert($(“#myselect option:selected”).index();
    the above shows -1.

    • 2

      Hi Jojo,
      It’s not working because you probably don’t have the html select dropdown on the page or you are using incorrect ID. In your code, you are using #myselect. This means that your HTML select dropdown MUST have an ID of myselect. Unless this is fixed, it won’t work.

      In order to help you, I have added a complete example that shows you exactly how to do it. Just refer to the example above and try it out & let me know how that goes.

  2. 3

    You actually make it seem so easy with your presentation but I find this matter to bbe really
    something thqt I think I would never understand. It seems too
    complex and very broad for me. I am looking forward foor your next post, I will try to get thhe hang of it!

Share your thoughts, comment below now!



CommentLuv badge