开发者

How do I loop through a menu in jQuery?

开发者 https://www.devze.com 2023-02-10 04:51 出处:网络
I was wondering how I can loop through html menus with jQuery just like in text fields e.g. $(\"#table input[\'type=te开发者_如何学运维xt\']\").each(function(){

I was wondering how I can loop through html menus with jQuery just like in text fields e.g.

$("#table input['type=te开发者_如何学运维xt']").each(function(){

});

How do I do the same for drop down menus?


Just change the selector to match the elements in the <select> element, which are <option> elements:

$("#select option").each(function(){

});


To loop through your menu items or any element just specify which class or element you want to loop through.

List:

$("#menu li").each(function(){
    alert($(this).val()); // Alert demonsatrating option value
});

Dropdown's

$("#menu option").each(function(){
    alert($(this).val()); // Alert demonsatrating option value
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号