How To Add First Options To A Select Element Using JQuery

You can add the first option to a select element using jQuery by using the prepend() method to add a new option element to the beginning of the select element’s options.

  1. Create a HTML Code:
    <!DOCTYPE html>
        <script src="">
          Select one of the proposed options:
          <select id="mySelect">
            <option value="option1">Option 1</option>
            <option value="option2">Option 2</option>

    2. Create JavaScript Code:

<script type="text/javascript">    
      jQuery(document).ready(function () {
        var optionText = 'Option';
        var optionValue = 'option';

In this example, mySelect is the ID of the select element to which you want to add the first option. The prepend() method is used to add a new option.



Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories