How To Get All The Options From A Select Element In A List April 01, 2024 Post a Comment Using jquery (or native js). How do I get all the options html in a list, so the output is something like: var options = ['---------Solution 1: You can get the select node and find all the options in the select node and get the html from those options.var selectNode = $('select-selector'); var options = selectNode.find('option').toArray().map(function (o) { return o.outerHTML}); CopyEdit as per suggestion from comment by Rory. $.map(selectNode.find('option'), function(o) { return o.outerHTML; }); CopySolution 2: Something like this?Baca JugaDisplay Files In Directory Using Php And JqueryChrome.hid.send Fails On Second UseJquery/javascript Convert A Plain Text Message Into A Text Input Fieldvar selectBoxEl = document.getElementById('selectBox'); var arrayOfNodes = selectBoxEl.childNodes; var optionsArr = []; // loop through child Nodes and only get option nodesfor (var i = 0; i < arrayOfNodes.length; i++) { if (arrayOfNodes[i].nodeName === 'OPTION') { optionsArr.push(arrayOfNodes[i].outerHTML); } } console.log(optionsArr);Copy<selectid="selectBox"><optionvalue="volvo">Volvo</option><optionvalue="saab">Saab</option><optionvalue="mercedes">Mercedes</option><optionvalue="audi">Audi</option></select>Copy Share You may like these postsCanvas.todataurl() Tainted Canvases May Not Be ExportedUpdate Options In Select DynamicallyHighcharts: How Do I Change The Legend Location In The Export Of A Chart?Jquery: Hide Children, Show Nth Child? Post a Comment for "How To Get All The Options From A Select Element In A List"
Post a Comment for "How To Get All The Options From A Select Element In A List"