Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  7] [ 1]  / answers: 1 / hits: 98933  / 11 Years ago, thu, october 17, 2013, 12:00:00

I need to return true or false if an option in a drop down selected.



This is my code:



var active = sort.attr('selected') ? return true : return false;


I get an error that the first return is unexpected.



Why?


More From » jquery

 Answers
80

You cannot assign a return statement to a variable. If you want active to be assigned the value true or false, just delete the returns:



var active = sort.attr('selected') ? true : false;


or maybe better:



var active = sort.prop('selected');


since .prop always returns true or false, regardless of the initial tag attribute.


[#74912] Wednesday, October 16, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tomas

Total Points: 165
Total Questions: 111
Total Answers: 103

Location: Maldives
Member since Tue, Dec 21, 2021
2 Years ago
tomas questions
Thu, Jan 27, 22, 00:00, 2 Years ago
Mon, May 10, 21, 00:00, 3 Years ago
Tue, Jan 5, 21, 00:00, 3 Years ago
;