jQueryはjavascriptの拡張なので、外部ファイル化もjavascriptと同じ。
外部jQueryファイル:script.js
1 2 3 | $( function (){ $( '#sample1' ).hide(); }); |
HTNL本体
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional// < head > < meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" /> < title >jqueryサンプル</ title > < script src = "jquery-1.7.1.js" ></ script > < script src = "script.js" ></ script > </ head > < body > < ul > < li id = "sample1" >GreenDay</ li > < li id = "sample2" >Oasis</ li > < li id = "sample3" >Nilvana</ li > </ ul > </ body > </ html > |