Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery .val() and google closure compiler

I want to select the first option in a control so I write:

$("#MySelect").val($("#MySelect option:first").val());

Now go ahead and copy-paste the following into the google closure compiler:

// ==ClosureCompiler==
// @output_file_name default.js
// @compilation_level ADVANCED_OPTIMIZATIONS
// @externs_url http://closure-compiler.googlecode.com/svn/trunk/contrib/externs/jquery-1.7.js
// ==/ClosureCompiler==

$("#MySelect").val($("#MySelect option:first").val());

You'll get this error:

enter image description here

I don't see why the compiler is complaining! What's the problem?

Thanks for your suggestions.

like image 295
frenchie Avatar asked Feb 25 '26 23:02

frenchie


1 Answers

You could do this $("#MySelect").prop("selectedIndex", 0)​​​​. It's simpler and passes closure compiler.

like image 191
Esailija Avatar answered Feb 27 '26 12:02

Esailija