html - Adding option to select dynamically with jquery is producing side effects -


my jquery script:

var categorias = ["a","b","c"];  $(document).ready(function ()    {       $.each(categorias, function(index,item){       $("#mycategoria").append(new option(item))   });  }); 

my html:

<!doctype html> <html> <head>     <title>inserir obra</title>     <meta charset="utf-8"/>     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">    </script>     <script src="categorias.js"></script>     <script src="instrumentos.js"></script>     <script src="obra.js"></script> </head> <body>     <h3>inserir obra</h3>              <label for="mycategoria">categoria: </label>             <select id="mycategoria" name="categoria"/>              <p>isto é um teste</p> </body> </html> 

the problem:

when open html page p element swallowed select. why?

i think need close select tag...

<label for="mycategoria">categoria: </label>             <select id="mycategoria" name="categoria">             </select>  <p>isto é um teste</p> 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -