I looked at several posts about adding jquery in developing a chrome extension - but most are old and use manifest options that were deprecated (such as "background_page"). I have already added the "content_scripts" member. I still get "Uncaught ReferenceError: $ is not defined ".
Taking the simplest possible scenario - building upon Chrome's extension sample to add jquery to it - we would have something like:
Manifest:
{ "manifest_version": 2, "name": "myExt", "description": "myExt Desc", "version": "1.0", "browser_action": { "default_icon": "icon.png", "default_popup": "popup.html" }, "content_scripts": [ { "js": [ "jquery.js", "myScript.js" ], "matches": [ "http://*/*", "https://*/*" ] } ] }
myScript.js:
//var myObj = { // execute: function () { // $("#btn1").click(function () { // alert('I was clicked indeeeed!'); // }); // } //} //document.addEventListener('DOMContentLoaded', function () { // myObj.execute(); //}); $("#btn1").click(function () { alert('iae'); });
popup.html:
<html>
<head>
<title>Getting Started Extension's Popup</title>
<style>
body
{
min-width: 357px;
overflow-x: hidden;
}
img
{
margin: 5px;
border: 2px solid black;
vertical-align: middle;
width: 75px;
height: 75px;
}
</style>
<!--
- JavaScript and HTML must be in separate files: see our Content Security
- Policy documentation[1] for details and explanation.
-
- [1]: http://developer.chrome.com/extensions/contentSecurityPolicy.html
-->
<script src="myScript.js"></script>
</head>
<body>
<table>
<tr>
<td>
Hey
</td>
<td>
There
</td>
</tr>
<tr>
<td>
This is an extension!
</td>
<td>
<input type="button" id="btn1" value="Click Me" />
</td>
</tr>
</table>
</body>
</html>
I have all files in the same directory (popup.html, icon.png, manifest.json, myScript.js, jquery.js). There are no errors whatsoever in the html, nor in the script. The only error I get upong clicking [Inspect popup] is: Uncaught ReferenceError: $ is not defined
What am I missing ?!?