Reputation: 434
I have installed Eclipse along with the Web Developer tools -- I am trying to do Javascripting in Eclipse but wanted to know if there are specific other plug-ins/kits I need in order to do so. Currently I build using:
File -> New -> Web -> Dynamic Web Project ||
File -> New -> HTML File ||
File -> New -> JSP File
To be able to run JavaScript as the materials I am learning/working off of. However I am unable to have any JavaScript event handling capabilities in the Eclipse environment.
As an example I have the following HTML file:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<script src="keyboardTest.js"></script>
<title>pageTest</title>
</head>
<body>
</body>
</html>
---------------------
And keyboardTest.js file:
---------------------
alert("inside keyboardTest.js");
var main = function(){
$(document).keypress(function(event){
alert("HERE");
if(event.which === 65){
/** A **/
alert("A");
}
else if(event.which == 69){
/** E **/
alert("E");
}
else if(event.which===70){
/** F **/
alert("F");
}
else if(event.which===32){
/** SPACE_BAR **/
alert("space_bar");
}
});
}
$(document).ready(main)`
But the HTML doesn't trigger the Javascript within the inner function main--it does however send the very first ALERT(). Concurrently when I move the files to a directory on my computer the javascript ALERT works, but not the event readers.
Upvotes: 1
Views: 323
Reputation: 1868
You're using jQuery syntax here: $(document)
But you haven't included the jQuery framework to you html file. Add jQuery and it should work:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
Upvotes: 1