jQuery: find the for a selected value in a <select> element

前端 未结 2 912
被撕碎了的回忆
被撕碎了的回忆 2021-02-20 09:48

I have a dropdown menu with different option groups. If someone selects an option, how can I check which optgroup it belongs to? For example if \'ferrari\' were selected, how wo

2条回答
  •  一生所求
    2021-02-20 10:49

    Well, in pure js:

    this.options[this.selectedIndex].parentNode.label
    

    Not a single function call and less code to boot. :-)

提交回复
热议问题