The issue with the JQuery Cookie Plugin is that it is unable to function properly due to the

Although I know there are many similar questions out there, please bear with me. I am not as proficient in JQuery as I am with HTML/CSS, and this is my first time using cookies. On my website, I have a green banner that should disappear when the user clicks the 'X' icon.

The JQuery code below is causing me a lot of frustration:

$(document).ready(function(){ 
    if (!$.cookie('thecookie') || $.cookie('thecookie')==null || $.cookie('thecookie')=="") { 
        $("#headershadow").hide();
        $("#bigx").click(function(){
            $("#greenbanner").hide(1000);
            $("#headershadow").show();
            $.cookie('thecookie', 'true', { expires: 1, path: '/' });
        });
    } else {
        $("#headershadow").show();
        $("#greenbanner").hide();
    }
});

I need to understand why this code is not working properly. The goal is for the #greenbanner to be visible when the website loads initially, and then disappear for the day once the bigx is clicked. I am utilizing this JQuery cookie plugin.

Any assistance in fixing this issue and making it work correctly would be greatly appreciated. I have spent quite some time trying to figure this out and I'm starting to get frustrated.

Answer №1

It is important to note that in your code, jQuery is being included after the cookie plugin, which relies on jQuery.

<script src="jquery.cookie.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>

To resolve this issue, simply switch the order of these scripts as shown below:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<script src="jquery.cookie.js"></script>

In addition, you may also want to address any errors appearing in your console before proceeding with further troubleshooting.

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

Curved edges on a text box featuring a scroll bar

I'm facing an issue with my website where I have a large amount of text in an html textarea that requires a scroll bar. The problem is, I'd like to add rounded corners to the textarea, but it doesn't look good with the scroll bar. Below is ...

Is it possible to send information in an AJAX request without using the data key?

When making an Ajax call to a Rails 4.2 app that is configured with devise, I use the following code: $.ajax url: '/some_ajax_call', type: 'POST', dataType: "json", beforeSend: (xhr) -> xhr.setRe ...

Using jQuery, select the line immediately following the last `<br>` tag and apply a `<span>` tag to style it

Current code snippet to work with: <div class="desc-wrapper">Dr <br> Credentials<br> Lecturer</div> I am trying to extract the text following the last <br> tag and then insert <span></span> between Lecturer in or ...

css - align the arrow to the right in a dropdown

I recently started using a Bootstrap dashboard template created by Creative Tim. I am attempting to incorporate a dropdown list into a table cell, following the standard Bootstrap format: <div class="btn-group"> <button type="button" class="b ...

Tailored API endpoint for WooCommerce Cart Addition

I've been working on creating a custom API endpoint for adding products to the cart. Everything was running smoothly on my local environment, but when I went live, I encountered this error: Call to a member function generate_cart_id() on null Below i ...

Extract the URL parameter and eliminate all characters following the final forward slash

Here is the URL of my website: example http://mypage.com/en/?site=main. Following this is a combination of JavaScript and PHP code that parses the data on the site. I am now looking for a piece of code that can dynamically change the URL displayed in the ...

Tips for shifting a div to the left with AngularJS

I am working with a div structure that looks like the following: <div class="col-xs-1 scroll-button"><i class="glyphicon glyphicon-chevron-left"></i> </div> <div class="customer-ust-bant col-xs-22" id="letters"> <box n ...

I created a customized version of jQuery tabs, but I am looking for an external link to display the tab content and to style the original navigation

I've been experimenting with modifying a tabs script in jQuery that I came across. It seems like my attempt to enhance it has made things more complex than necessary. While I know creating tabs with jQuery is simple, I wanted to create my own version ...

JavaScript Button with the Ability to Input Text in a TextArea?

For instance, imagine a scenario where you click on a button and it then displays various options for you to select from. Whatever option you pick will be automatically inserted into the text area. ...

In HTML5, a full-width video exceeds the size of the screen

When I have a video set to full width in a header with the width at 100%, the issue arises with the height. The video is too large, causing the controls to be out of view unless I scroll. Is there a solution to remedy this problem? <video width="100%" ...

Clear HTML

Is there a way to create a 'div' element in an HTML document and adjust the background transparency using CSS or Javascript/JQuery in order to achieve a look similar to Simple Calendar Widget or Glass Widgets from Android? I have tried using the ...

Bootstrap resource failed to load

I successfully connected the most recent version of bootstrap.min.css to my webpage using <link rel="stylesheet" href="assets/css/bootstrap.min.css">. Initially, everything was running smoothly. However, I now encountered an issue where my browser is ...

Adding dynamically fetched JSON to an existing table

http://jsfiddle.net/mplungjan/LPGeV/ What could be improved in my approach to accessing the response data more elegantly? $.post('/echo/json/',{ "json": JSON.stringify({ "rows": [ { "cell1":"row 2 cell 1", "cel ...

Creating an Array of dynamically generated elements using jQuery

A dynamic table is being generated using jQuery's .append() function: $el.append('<tr data-id=' + data[i].id + ' data-token=' + data[i].token + '><td>' + data[i].order + '</td>\n\<td&g ...

Create a copy of a JQuery slider

Hello there, I'm a first time poster but have been reading for a while now. I've been working on creating a simple jQuery Slider and I'm facing an issue... I want to create a slider that utilizes minimal jQuery and can be easily duplicated o ...

Exploring the Open method in AJAX and its impact on synchronicity

I am in the process of creating a webpage that utilizes the openweathermap.org API. However, I am encountering an issue when making an AJAX call and trying to access the API using weather.open(blah, blah, true). function executeWeatherCity(cityName){ ...

Prevent horizontal scrolling when dragging in GWT

Incorporating a celltable within a scroll panel allows for vertical scrolling through all the items. Utilizing the gquery plugin enables drag and drop functionality, but I am currently facing an issue with dragging an item from one table to another. When ...

Occupying both horizontal and vertical space in a Bootstrap column

I have set up my buttons like this: https://i.stack.imgur.com/OMfhp.png In the image, you can see that the Left Option Button is larger, and I want all buttons to be like that. They are supposed to be aligned next to each other as I am using the Bootstra ...

Mastering the art of reading rows in ASP.NET using Java Script

Within the code snippet below, you'll find an image located in the second column. Clicking on this second column should allow me to access the data stored in the first column. Let's say we have a table with 10 rows. If the user clicks on the ico ...

Is it possible to deinitialize data tables (remove from memory)?

I'm currently utilizing data-tables (with jQuery) on my website. The particular data-table I have implemented seems to be consuming excessive memory in javascript, causing a slowdown in other functionalities. Is there a way for me to de-initialize th ...