tags:

views:

4189

answers:

3

Hi , How to count the number of options in a select Dom Element using JQuery.

   <select data-attr="dropdown" id="input1">
   <option value="Male" id="Male">Male</option>
   <option value="Female" id="Female">Female</option>
   </select>

How to find the number of options tag in the select DOm element since with that i want to open the Settings panel with that number of input fields with the corresponding option value from the dropdown box in it and to change it again in the Preview panel.Where the above dropdown box is in my preview panel which is generated by JQuery.

+3  A: 

Your question is a little confusing, but assuming you want to display the number of options in a panel:

<div id="preview"></div>

and

$(function() {
  $("#preview").text($("#input1 option").length + " items");
});

Not sure I understand the rest of your question.

cletus
+1  A: 

The W3C solution:

var len = document.getElementById("input1").length;
karim79
+13  A: 
$('#input1 option').size();

will produce 2

nightingale2k1