Home  »  CodeProgrammingSnippetsTechnology   »   How to Use jQuery to Add option to HTML Select Element

How to Use jQuery to Add option to HTML Select Element

Posted: August 3, 2022 | by Michael Bright

This is how to add option to an HTML select element with jQuery.

Method 1:

$('#selectElementId').append($('<option>', {
    value: 1,
    text: 'Option Text'
}));

Method 2:

$("#selectElementId").append(new Option("Option Text", "1")); // where 1 is the value

Method 3:

$('#selectElementId').append('<option value="1">Option Text</option>');

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.