xxxxxxxxxx
// Get the selected text from the dropdown
const selectedText = $("select option:selected").text();
// Print the selected text
console.log(selectedText);
xxxxxxxxxx
$("#myDropdown option:contains(Option 2)").attr('selected', 'selected');
xxxxxxxxxx
// Getting the selected option text
var selectedOptionText = $("select option:selected").text();
// Outputting the selected option text
console.log(selectedOptionText);
xxxxxxxxxx
I think this should be $("#yourdropdownid").children("option").filter(":selected").text() since is() returns a boolean of whether the object matches the selector or not.