How should I understand
$("select option:selected")
in the following code ?
(taken from here)
$("select").change(function() {
...
$("select option:selected").each(function () {
...
});
...
})
Is it all selected options in all selects in the document ?
Is it somehow related to the current select, $(this) ?
Yes, it will refer to all selected options in all selects. If you just want to look at the current select, you can do something like this:
$("select").change(function() {
...
$(this).find("option:selected").each(function () {
...
});
...
})
It's selected options from whole document.
You can use find
to select only from $(this)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With