-3

I am learning JavaScript and I am planning to make a Chrome extension. I am making an Age Calculator. I have developed some code. I am stuck at how to use jQuery in an external JavaScript File?

if (ageYears > 0) {
    document.write(ageYears +" year");
    if (ageYears > 1) document.write("s");
        if ((ageMonths > 0)||(ageDays > 0)) document.write(", ");
    }
    if (ageMonths > 0) {
        document.write(ageMonths +" month");
        if (ageMonths > 1) document.write("s");
        if (ageDays > 0) document.write(", ");
}
if (ageDays > 0) {
    document.write(ageDays +" day");
    if (ageDays > 1) document.write("s");
}

manifest.json

{
    "name": "Age Calculator",
    "description": "This application gives you a calculation of how old are you today, since the day you were born.",
    "version": "0.1",
    "manifest_version": 2,

    "app": {
        "background": {
            "scripts": ["background.js"]
          }
    },
    "icons": { "128": "calendar-128.png" }
    "author" : "Miral Kumbhani"
}
Makyen
  • 31,849
  • 12
  • 86
  • 121
Miral Kumbhani
  • 153
  • 1
  • 3
  • 16
  • Can you send your manifest? – Manav Sep 15 '17 at 11:18
  • https://stackoverflow.com/questions/21317476/how-to-use-jquery-in-chrome-extension – TKoL Sep 15 '17 at 11:19
  • Please keep your Questions to one question per Question. Questions which contain multiple questions which are not *very* tightly related are considered too broad and tend to be closed. The reason for this is that the Stack Overflow format is intended to provide a base of questions and answers which are useful to people in the future, not just the person currently asking. Questions with multiple issues tend to be too specific to be useful to others searching for help to their problems. Often, to solve a larger issue it is necessary to combine the answers from multiple questions. – Makyen Sep 15 '17 at 18:30
  • I suggest you read the [Chrome extension overview](https://developer.chrome.com/extensions/overview) (perhaps along with the pages linked from the overview). The [architecture section](https://developer.chrome.com/extensions/overview#arch) has overall architecture information which should help your understanding of how things are generally organized/done. You will probably also want to read [Content Scripts](https://developer.chrome.com/extensions/content_scripts). – Makyen Sep 15 '17 at 18:31

1 Answers1

-1

Just get all of that code into an external JavaScript file and in your main file under where jQuery.js is linked link the file i.e

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="FILENAME.js"></script>
Demoncious
  • 21
  • 3
  • I have the JavaScript File named **background.js** and I actually want to use JQuery in that file. I have the main file as **index.html** And the code is a patch of a function. So, I don't want to make a separate JQuery File. – Miral Kumbhani Sep 15 '17 at 11:30
  • You can write the code in that file without having the need to create a second file. – Demoncious Sep 15 '17 at 11:36
  • But I am unable to actually run the JQuery when I put it in the Javascript file. – Miral Kumbhani Sep 15 '17 at 11:38