{"id":12263,"date":"2022-08-03T13:20:37","date_gmt":"2022-08-03T17:20:37","guid":{"rendered":"http:\/\/local.brightwhiz\/?post_type=snippets&p=12263"},"modified":"2022-08-03T13:20:40","modified_gmt":"2022-08-03T17:20:40","slug":"use-jquery-to-add-option-to-html-select-element","status":"publish","type":"snippets","link":"http:\/\/local.brightwhiz\/snippets\/use-jquery-to-add-option-to-html-select-element\/","title":{"rendered":"How to Use jQuery to Add option to HTML Select Element"},"content":{"rendered":"\n
This is how to add option to an HTML select element with jQuery.<\/p>\n\n\n\n
Method 1:<\/strong><\/p>\n\n\n\n Method 2:<\/strong><\/p>\n\n\n\n Method 3:<\/strong><\/p>\n\n\n\n$('#selectElementId').append($('<option>', {\n value: 1,\n text: 'Option Text'\n}));<\/code><\/pre>\n\n\n\n
$("#selectElementId").append(new Option("Option Text", "1")); \/\/ where 1 is the value<\/code><\/pre>\n\n\n\n
$('#selectElementId').append('<option value="1">Option Text<\/option>');<\/code><\/pre>\n","protected":false},"comment_status":"open","ping_status":"closed","template":"","meta":[],"categories":[953,27,15,16],"tags":[303,328,333,433,449,471,638],"yoast_head":"\n