I have a question as to how can I calculate number of options tag when I get the select box with $this.
Like that:
$("select[name=rabetas]").click(function(){
var $this = $(this);
And...?
how can I do this?
Select the <option>
elements , and then get the length
.
var numOptions = $this.children().length;
Learn to dig through the jQuery API docs . They will answer 99% of your questions.
If you want to loop through a collection of select list items, inspecting the DOM will show that each item has an object array with one item so you can use the following code...
$('.myddlclass').each(function (index) {
var options = $(this)[0].options.length;
});
If I understand what you're trying to do, I believe you can use
$("select[name="rabetas"] option").size();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.