jquery loop through select options set selected

I was just wondering if it's possible to go through multiple select options and get their values and text(if one is selected get the value and text, if 2 is selected get both of their values and text and so on). Event binding on dynamically created elements? Why did the Soviets not shoot down US spy satellites during the Cold War? Story Identification: Nanomachines Building Cities. The .attr () method returns undefined for those attributes that have not been set for jQuery 1.6 version. I tried using addClass but it is not working, How do I loop through options in the select box, The open-source game engine youve been waiting for: Godot (Ep. How can I do that for select inputs that aren't already selected as value='2'? Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide, It doesn't matter if it's already selected - just set it again and jQuery will deal with it for you. Using this, elements can be traversed easily. The example specifies the value Two to select on button click. By clicking Post Your Answer, you agree to our terms of service, privacy policy and cookie policy. Using jQuery With jQuery, you can use the .each () method, which is a concise and less error-prone way to iterate over the DOM elements. Why was the nose gear of Concorde located so far aft? A better alternative is to use the jQuery.map() instead. You JQuery Code $ ("#mySelectionBox option").each (function () { alert (this.text + ' ' + this.value); }); OR var select = $ ('#mySelectionBox') [0]; for (var i = 0; i < select.length; i++) { var option = select.options [i]; alert (option.text + ' ' + option.value); } Share Improve this answer Follow edited May 15, 2018 at 4:27 Has Microsoft lowered its Windows 11 eligibility criteria? Can the Spiritual Weapon spell be used as cover? How to iterated through selected