Tips for resolving issues with JS and JQuery not functioning properly in a Chrome extension

Currently configuring a chrome extension and have successfully constructed the settings menu with functional CSS and HTML. Utilizing this button from Codepen, which confirms error-free code via https://i.sstatic.net/0yG0l.png. How should I define the function? Recently downloaded jquery into the directory, calling it through script as shown in this https://i.sstatic.net/qgOUF.png link since using CDN faced security restrictions during extension development.

$('button.cooldown').click(function(){
  var btn = $(this);
  btn.prop('disabled', true);
  setTimeout(function(){
    btn.prop('disabled', false);
  },15000);
});
// Styles for various elements here...
<html>
<head>
  <title>Home+</title>
  <link rel="stylesheet" type="text/css" href="popup.css">
  <script src="popup.js"></script>

  <div id="header">
    <h2>Home+</h2>
    <h6>Settings</h6>
  </div>
</head>

<body>

  <!-- Settings pane content -->
  <div class="tab-pane" id="settings">
    <form class="settings">
      </div>
    </form>

  </div>
</body>
</html>

Answer №1

The CodePen you provided includes jQuery as an external library, which can be found in the Settings section of the CodePen page under JavaScript.

To ensure your extension functions properly, make sure to include jQuery in the extension.

Here is a working example where I've added

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
to the HTML before including popup.js:

$(() => {
    $('button.cooldown').click(function(){
    var btn = $(this);
    btn.prop('disabled', true);
    setTimeout(function(){
      btn.prop('disabled', false);
    },15000);
  })
});
body {
  background-image: linear-gradient( 72.5deg,  rgba(0,175,255,1) 27.9%, rgba(0,224,254,1) 84.2% );
  width: 250px;
  height: 400px;
}

#header {
  padding-top: 2px;
  padding-bottom: 2px;
  text-align: center;
  background-color: #393e46;
  color: white;
  font-size: 15px;
  border-radius: 10px;
}
/* Additional CSS code here */

/* The container */
.container {
  display: block;
  /* more styles */
}

/* Hide the browser's default checkbox */
.container input {
  position: absolute;
  opacity: 0;
  // more styling
}

/* Create a custom checkbox */
.checkmark {
  /* more styles */
}

/* On mouse-over, add a grey background color */
.container:hover input ~ .checkmark {
  /* more styles */
}

/* When the checkbox is checked, add a blue background */
.container input:checked ~ .checkmark {
  /* more styles */
}

/* Create the checkmark/indicator (hidden when not checked) */
.checkmark:after {
  /* more styles */
}

/* Style the checkmark/indicator */
.container .checkmark:after {
  /* more styles */
}

/* additional CSS for form elements and buttons */
/* layout stuff */
section {
  text-align: center;
  margin-top: 100px;
  color: #333;
}
p {
  font-size: 12px;
}
<html>

<head>
  <title>Home+</title>
  <link rel="stylesheet" type="text/css" href="popup.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
  <script src="popup.js"></script>

  <div id="header">
    <h2>Home+</h2>
    <h6>Settings</h6>
  </div>

</head>

<body>


  <!-- The settings pane, expand at will -->
  <div class="tab-pane" id="settings">
    <form class="settings">
      <div class="form-item">
        <label for="zip">Zip Code: </label>
        <div class="form-item">
          <input id="zip" name="zip" type="text" pattern="[0-9]*">
        </div>
      </div>

      <div class="form-item">
        <label class="container">Show Weather
          <input type="checkbox" checked="checked">
          <span class="checkmark"></span>
        </label>
      </div>


      <div class="form-item">
          <button class="cooldown">Refresh Weather</button>
      </div>



      <div class="form-item">
        <label for="hompagebg" class="wallpaper-title">Upload Wallpaper</label>
        <center>
          <input type="file" id="hompage-background" name="hompagebg" accept="image/png, image/jpeg" size="20">
        </center>
      </div>


      <div class="form-item">
        <button type="button" class="button">Save</button>
        <button type="button" class="button_cancel">Cancel</button>
      </div>

    </form>

  </div>

  </div>


</body>

</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What drawbacks should be considered when utilizing meteor.js for development?

After viewing the meteor.js screencast, I was truly impressed by its seamless web application development capabilities, especially in terms of live updates and database synchronization. However, I am curious about its scalability once the website goes live ...

The duration of time separating each individual post

After receiving approval for publish_actions on my app, I am currently attempting to comment on feed posts. Everything is functioning smoothly. Here is the code that is working: function home(token){ jQuery.ajax({ url:'https://graph.facebook.com ...

Is it possible for me to convert the contents of a <div> into a rasterized image when printing?

I have been using jquery.printElement.js to print a custom calendar table that I created. The functionality inside a div is mostly working as expected, but I am facing some challenges with the CSS. Despite passing along all necessary .css files, my cells a ...

React Semantic UI Grid and Div components can be toggled by using a button to decrease

My goal is to create a menu that initially displays with a certain width, but when a button is clicked, it will decrease the width to 50px and only show the icon. I'm struggling to figure out how to adjust the width of my div and integrate this funct ...

The requested resource does not have the 'Access-Control-Allow-Origin' header, resulting in a 401 error

I've been working on integrating spell check functionality using the Bing Spell Check API, but I've run into a 401 error. The specific error message is: The requested resource does not have an 'Access-Control-Allow-Origin' header. This ...

Utilize date-fns to style your dates

Struggling to properly format a date using the date-fns library. The example date I'm trying to work with is 2021-09-20T12:12:36.166584+02:00. What am I doing wrong and what is the correct approach? Here's the code snippet I have so far: import ...

Using $watchGroup to monitor changes in an array and automatically updating it

Issue: I am facing a challenge where I want to pass an array of variables into $watchGroup and iterate through the array to update the values of each element. However, the current approach I am using does not seem to be effective: $scope.secondsElapsed = ...

Using Vue.js to toggle rendering based on checkbox selection

Struggling to conditionally render form elements in Vue based on user input. I can do this with VanillaJS or jQuery, but struggling to implement it with Vue's built-in conditional directives. Using single-file components with the webpack template from ...

Angular's focus function poses certain challenges that need to be addressed

I am seeking assistance as a new programmer facing a beginner's challenge. I have two inputs and I would like to enter a series of numbers in the first input (DO) and have them automatically populate in the second input (communal code). Inputs: http ...

What is the best way to toggle a d3 svg overlay using a leaflet layer control?

I am looking for a solution to place 3 d3 svgs on a leaflet map and control them as easily as leaflet layers. Check out this code example, which works but is not ideal. The key part is from line 75 onwards, where I create a custom layer control linked to ...

The current issue lies with the lack of functionality in the Ajax post feature

Seeking assistance here. I've encountered a frequent issue on stackoverflow and despite attempting various methods, none seem to be working for me. Could it be that I'm doing something fundamentally wrong? Here is the code snippet in question: $ ...

Tips for enhancing contrast in MUI dark theme modals

Currently, I am implementing MUI dark mode for my Next.js application. While the MUI modal functions perfectly in light mode, I am struggling with visibility issues when using it in dark mode. The contrast is not strong enough, making it difficult to disti ...

Problem with OnClick function in Firefox

I have implemented the following code in an external JavaScript file: $( document ).ready(function() { var elem='<img class="imgload" src="/common/images/spinLoader/transperent.png">'; $('.imgchange').append(elem); }); $(func ...

The built-in functions of Wordpress are not able to be identified in the ajax PHP file

As a newcomer to Wordpress development, I am facing challenges with implementing ajax on my WordPress site. I am currently working on a plugin that requires the use of ajax. However, my php file (xxxecommerce.ajax.php) is not recognizing the built-in Word ...

Discovering hidden elements using Overflow:hidden

I need help figuring out how to display the cropped part of my text without using scroll bars in css. For example: td { overflow: hidden; } The hidden content is important, but the table property is fixed. table { table-layout: fixed; } I want the ...

Loading intersecting objects with FBXLoader in Three.js

After successfully loading an fbx file using FBXLoader and adding it to the scene object, I encountered an issue where I couldn't interact with the object on click to apply transform controls. Interestingly, all other objects were clickable except for ...

Building a flexible table in React JS based on specific keys: a complete guide

I'm currently working on developing a dynamic table component using React JS. The component at the moment has a fixed header with the most common result keys. Some results contain additional information such as phone numbers and degrees. I'm loo ...

EdgesGeometry: raycasting precision issues

I'm currently working with EdgesGeometry on PlaneGeometry and it appears to be creating a larger hitbox in mouse events. Interestingly, this issue doesn't arise when using CircleGeometry. Below is the code snippet I am using: createPanel = f ...

Ensure that the link's color remains constant and remove any styling of text-decoration

Attempting to create a customized header. My goal is to change the color and remove text decoration in the navbar. Below is my code snippet: ReactJS: import React from 'react'; import './Header.css'; function Header() { return ( ...

Tips for indicating request parameters in Drive.Comments.list

I have successfully retrieved the default 20 comments using the code below by specifying a single fileId parameter. However, I am interested in pulling back one hundred comments or paginating to the next set of 20 out of curiosity. In my getComments funct ...