javascript - Can't get jQuery to work in index.js in Blank Cordova App in Visual Studio 2015 -
i using visual studio 2015 create blank apache cordova app shown in link: http://i.imgur.com/1pl3el0.png
using nuget package manager, i've added jquery project: http://i.imgur.com/smhvnyz.png
from basic understanding, adding jquery through nuget manager doesn't add script tag index.html (or index.js) instead get's packaged in cordova.js file.
i've added following basic link tag in index.html <a href="#" id="mylink">link</a>
however, if try reference anchor tag using jquery in index.js file, following error: uncaught referenceerror: $ not defined
however, in debug window, in javascript console, can use jquery fine access elements. missing basic here. can explain why jquery failing?
here index.html , index.js files:
index.html:
<!doctype html> <html> <head> <meta charset="utf-8" /> <!-- customize content security policy in meta tag below needed. add 'unsafe-inline' default-src enable inline javascript. details, see http://go.microsoft.com/fwlink/?linkid=617521 --> <meta http-equiv="content-security-policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *"> <title>office365test3</title> <!-- office365test3 references --> <link href="css/index.css" rel="stylesheet" /> </head> <body> <p>test 3</p> <br /> <a href="#" id="mylink">link</a> <!-- cordova reference, added app when it's built. --> <script src="cordova.js"></script> <script src="scripts/platformoverrides.js"></script> <script src="scripts/index.js"></script> </body> </html>
index.js
/// <reference path="../../scripts/jquery-2.1.4.min.js" /> /// <reference path="../../scripts/jquery-2.1.4.min.js" /> // introduction blank template, see following documentation: // http://go.microsoft.com/fwlink/?linkid=397704 // debug code on page load in ripple or on android devices/emulators: launch app, set breakpoints, // , run "window.location.reload()" in javascript console. (function () { "use strict"; document.addeventlistener( 'deviceready', ondeviceready.bind( ), false ); function ondeviceready() { // handle cordova pause , resume events document.addeventlistener( 'pause', onpause.bind( ), false ); document.addeventlistener( 'resume', onresume.bind( ), false ); // todo: cordova has been loaded. perform initialization requires cordova here. $('#mylink').css('display', 'none'); }; function onpause() { // todo: application has been suspended. save application state here. }; function onresume() { // todo: application has been reactivated. restore application state here. }; } )();
try moving jquery files www/scripts
directory, , reference them index.html
file. default, nuget places them in scripts
folder in project root, doesn't seem accessible.
Comments
Post a Comment