jquery - add item to dropdownlist when dropdownlist's display is none -


i have aspx dropdown list , its' display none. i'm adding items array dropdownlist it's not working. here script code.

  var array = $("#listed h1").toarray();       $("#mydiv").append($("#mydrop"));       $("#mydrop").show();        (var = 0; < array.length; i++) {          var id = "#" + array[i].id;          var newoption = "<option value ='" + + "'>" + $(id).text() + "</option>";          $("#mydrop").append(newoption);       } 

can me i'm doing false? thanks.

you provided no html work have guess html looks js.

it seems might have <h1>s inside <div> , <select> blank , hidden default.

then on page ready want populate select options represent <h1>s value being index represents order displayed in, , text being text of <h1>.

this of course bunch of assumptions have made based on limited information provided.

alright here attempt understand question. update answer provide more information.

https://jsfiddle.net/w5vkeswr/

$("div h1").each(function(i, el){  	$("select").append("<option value='"+i+"'>"+el.innerhtml+"</option>");  });  $("select").show();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div>    <h1>item 1</h1>    <h1>item 2</h1>    <h1>item 3</h1>  </div>  <select style='display: none;'></select>


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -