Display a <div> every hour

I am attempting to display a <div> element once every hour. However, the code seems to be malfunctioning when I include the following:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div id='showOnceAnHour' style='display: none'>
<script>
$(document).ready(function() {
    setInterval(function() {
        $("#showOnceAnHour").fadeIn().delay(10000).fadeOut();
    }, 60*60*1000);
});
</script>

The code runs fine without this addition, but my goal is to show that content only once per hour. Please review and advise me on what may be going wrong.

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<style>

<!-- Some CSS Styles -->

</style>
</head>

<body>
<div id='showOnceAnHour' style='display: none'>
<script>
$(document).ready(function() {
    setInterval(function() {
        $("#showOnceAnHour").fadeIn().delay(10000).fadeOut();
    }, 60*60*1000);
});
</script>

<!-- Modal -->
<!-- HTML for a modal pop-up box -->

</body>
</html>

Answer №1

Trying to utilize jQuery selectors without importing the jQuery library? Easily fix this by including the following line in your HTML head:

<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>

Answer №2

Ensure that you have included the JQuery CDN or a static import in your code.

 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div id='showOnceAnHour' style='display: none'><h1>Div</h1></div>
<script>
$(document).ready(function() {
    setInterval(function() {
        $("#showOnceAnHour").fadeIn().delay(10).fadeOut();
    }, 60);
});
</script>



<h3>I Just changes the fadeIn and fadeOut time for demo purpose</h3>

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

Padding will not completely fill the <li> and <div> elements

Looking to create a sleek menu bar that's 40px tall and fills up 80% of the browser width. The challenge arises when trying to center the text within the menu items. Despite adjusting padding for alignment, there's still a small gap because of & ...

The i18next plugin initialization does not include the implementation of 'resGetPath'

I'm having trouble setting up the resGetPath attribute in i18next to access translation.json files locally. When I initialize the plugin with the resources object, everything works fine. However, when using the resGetPath attribute, I can't seem ...

Other options for positioning background in SVG or using CSS within SVG could include center center alignment settings

I am currently developing a website where I have a div covered by an SVG. When I use this SVG as a background image and apply background-position: center center, it functions as expected. However, my issue arises when I try to add additional CSS in this ma ...

Error: Value incorrectly displayed due to input range issue

There seems to be some confusion on this part. I set the initial value of an input range to 15, but when I tested it, the default value was 16. <input type="range" id="price" min="1" max="50" value="15" step="5"/> You can view the fiddle here: http ...

Is it feasible to select the last child of an input without having to specify the submit

Here is a portion of the HTML code I am currently testing: <form action="#" method="post> <input name="username" type="text" placeholder="Username" /><br /> <input name="password" type="password" placeholder="Password" />&l ...

A 'select all' checkbox in a PHP 'foreach loop' with JavaScript

I am in search of a solution to implement JavaScript in the given code block. My goal is to have the checkbox with id = alles automatically check all the checkboxes that are generated within the while loop. <form id="andere" name="andere" action="<? ...

Display a different GIF every time a page is visited or refreshed

I am incorporating the GIPHY API to showcase an image based on a query. The current code I have pulls the image successfully, but there is a recurring issue where the same GIF displays each time the website is visited until the query is altered. My aim is ...

The dropdown in vue-multiselect automatically closes after the first selection is made, ensuring a smooth user experience. However,

I am experiencing an issue where the dropdown closes after the first selection, despite setting close-on-select="false". However, it works properly after the initial select. You can observe this behavior directly on the homepage at the following link: vue ...

Two challenges I encountered with my CSS dropdown menu bar

I've been working on a CSS top dropdown navigation bar, but I'm encountering two issues that I can't seem to resolve. The first problem is that my nav div either extends too far down or my 1px right border tabs aren't reaching the botto ...

Design that adapts to various screen sizes and devices

I'm facing an issue where the two elements are misaligned on mobile, even though they display perfectly on desktop. In some cases, the bottom element is partially hidden on the left side as shown here: Any suggestions on how to center these elements ...

Issue: Unable to extract the 'title' property from '(0 , react__WEBPACK_IMPORTED_MODULE_1__.useContext)(...)' as it is not defined (Next.js Chat App)

Currently facing an issue with the error message "Cannot destructure property 'title' of '(0 , react__WEBPACK_IMPORTED_MODULE_1__.useContext)(...)' as it is undefined" while developing a chat application using Next.js and Solidity. Desp ...

Using Node.js to convert a file name to a timestamp

I need to change a filename into a timestamp in my Laravel application. let test = "/2020-05-16_11-17-47_UTC_1.jpg" I attempted using split and join to replace the -, but I don't believe it's the most efficient method. The desired output should ...

The JS slider fails to function properly following the migration of AngularJS from version 1.0.8 to 1.2

Seeking assistance with migrating AngularJS from version 1.0.8 to 1.2 and encountering issues with a JavaScript slider that is no longer functioning post-migration... After upgrading to 1.2, added the angular-route.js library and injected 'ngRoute&ap ...

Avoid allowing image uploads that are too large in size

Is there a way to block an image from being uploaded if it exceeds a specified size limit? Currently, I am using angular-base64-upload and although my error message appears when the image is too large, the image still gets uploaded. I'm puzzled as to ...

Arrange the data in the table to ensure that it is organized neatly into the appropriate columns

I am currently working on a project that involves creating a table to display user answers for purchased tickets under the corresponding questions. If a question has not been answered, I want to show a dash symbol instead. However, I am encountering an is ...

Storing binary data uploaded via AJAX in PHP on the server is essential for maintaining

I successfully imported a .png image file as an Array Buffer. var readSingleFile = function(e) { var file = e.target.files[0]; if (!file) { return; } var reader = new FileReader(); ...

Error: Trying to access 'MaterialModule' before it has been initialized results in an uncaught ReferenceError

I have been working on a form for a personal project and attempted to implement a phone number input using this example: . However, after trying to integrate it into my project, I encountered an error. Even after removing the phone number input code, the e ...

Querying data with parameters in a client-side rendered application with Next.js

Currently, I am developing a chat application using Next.js and Axios. One of the functionalities I implemented is a dynamic route called chat/:pid to fetch data using the provided pid. However, I encountered an issue where the values are coming back as un ...

Why isn't margin working with position: fixed?

I need help finding a solution for incorporating margin in a box within my App class. The issue is that the position fixed property doesn't seem to work as intended. <div className="App"> <div className="box"> ...

Learn how to effectively transfer data from $.getjson to PHP, specifically through the use of Laravel's @foreach loop

$.getJSON( 'http://localhost/media_books/index.php/new_books.json?provider_id=1&limit=99&offset=1') .done(function( json ) { $(tar).closest('.accordion').children('div').text(json); }); I have successfully obtaine ...