UncleCoder.com

UncleCoder.com

Free programming examples and instructions

jQuery append to select

Demo and Code for how to append options to select control

by Athil


Posted on 13 May 2017 Category: jQuery Views: 670

Edited on 03 Jun 2017


DEMO

Hi , Here I am going to show how to append option items into a select control using jQuery

 $("#Selectcontrol").append("<option>Pine apple</option>");

Full Code

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Demo for append to select control using jquery</title>
         <script type="text/javascript" src="js/jquery.min.js" ></script>
</head>
<body>
    <h1>Demo for append to select control using jQuery </h1>

    <select id="Selectcontrol"> 
    <option>Apple </option>
    <option>Orang</option>
        <option> grapes</option>

        </select>

    <button id="btnAppend" onclick="Append()"> Append pineapple to select </button>

    <script>
        function Append() {
            $("#Selectcontrol").append("<option>Pine apple</option>");
        }
        </script>
</body>
</html>

 



Leave a Comment:


Advertisement