How to get all key values from a dropdown box in jquery

If you want to get all the key and values from a select box just use below jquery code snippet.

$(function() {

    var values = {}

    $.each($("select").prop("options"), function(i, opt) {
        values[opt.value] = opt.textContent
    })
    console.log(values);
});

If you are finding same thing to do in javascript, you can go through with my another post how to get all key values from a select box in javascript

Please let me know in comment in case you are facing any issues with this code.

Leave a Reply