Continue applying CSS edits even after reloading the page

I have successfully implemented the Cookie Yes plugin with wordpress, however, there is one final issue that I need help with.

Our goal is to ensure that the banner always remains at the top of the page without overlapping the navigation bar. To achieve this, I had to add some additional CSS to make it stick to the top.

I also included a JS function that hides the banner and moves the nav back to the top when the user clicks on the confirm cookie link.

The problem I am facing is that upon refreshing the page, the styles are lost, leaving a large gap at the top where the banner used to be.

How can I make sure that these additional styles are retained? You can view the site here.

$(document).ready(function(){
 $('#cookieToggle').on('change', function(){
   const value = $(this).prop('checked');
   onCookieSelection (value);    
 });

function onCookieSelection (val) {
   $('#divAcceptCookiesConfirm').toggle(val);
   $('#divAcceptCookiesReject').toggle(!val);
 }  
 $('#cookieToggle').prop( "checked", true );
 onCookieSelection(true);

 $('#wt-cli-accept-all-btn').on('click', function() {
   $('html.has-not-scrolled #desktop-header').css('top', '0px');
   $('#mobile-header').css('top', '0px');
   $('main').css('top', '0px');
          
  });
   $('#wt-cli-reject-btn').on('click', function() {
       $('html.has-not-scrolled #desktop-header').css('top', '0px');
       $('#mobile-header').css('top', '0px');
       $('main').css('top', '0px');
   });
});

Answer №1

It seems like you're unsure about the method used to check if a cookie is set.

Let's consider a scenario where the is_cookie_set() function returns true or false, indicating whether the user has accepted the cookie.

To address this issue, you can implement the following solution:

$(document).ready(function(){
    if(is_cookie_set()){
        $('html.has-not-scrolled #desktop-header').css('top', '0px');
        $('#mobile-header').css('top', '0px');
        $('main').css('top', '0px');
    }
}

Please test this solution and let me know if it resolves the issue.

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

Display the information from a JSON array using an alert box

Similar Question: How can I access a specific value in a nested data structure or JSON? I am trying to display data from a JSON array using the following code, but it is not working: var Content = [{ "01":[{"text":"blablablablabla","foo":"abeille ...

Using Ajax with Controller Action in Yii2

As a newcomer to programming, I am facing an issue where I need to call a function when the user inputs data and clicks the submit button. Although I am working with Yii2, I lack experience in Ajax. Despite my efforts, the controller action is not being tr ...

How can Vue be used to dynamically alter a string within an input field by incorporating the status of checked checkboxes?

Yesterday, I stumbled upon a concise Vue presentation on YouTube before answering a technical question on Stack Overflow. The question involved generating checkbox elements based on a string of text containing '1's and '0's, with the ch ...

Personalizing the height and width of a jQuery UI Slider

While adjusting the height/width of the jQuery UI Slider and handle, I've noticed that the handle sometimes slides too far to the left, going off the slider. Is there a recommended way to prevent this from happening? You can see what I mean by checki ...

The function form.parse() in node.js is always overlooked

I'm having an issue where form.parse() is never called. When I delete bodyparser, my session variable throws an error. How can I resolve this and make it work? logcat The write(string, encoding, offset, length) method is deprecated. Use write(st ...

What is the procedure for transferring the inputted data from an HTML file to its corresponding TS file and subsequently to a different component file?

I have created two components, a login and a home-page. I am attempting to capture user input from the login template, pass it to the login component, and then display it on the home-page template using the home-page component. What is the best approach to ...

Using jQuery to implement conditional logic in HTML

Is there a way to exclude tags/variables in a jQuery HTML method? For example, if the company field is empty, it should not appear in the HTML. $('.modal-body').html(` <p><span style="font-weight:bold;">Name:< ...

Verify the presence of the element on the webpage before proceeding, utilizing Python to handle the scenario if

Having trouble resolving an issue that involves checking if a specific element is present on a page before executing a piece of code. Currently, when the element doesn't appear, the script fails with a 'Failed to find element' error. This i ...

Optimizing CSS for Improved Page Ranking

I'm currently working on styling the layout of my MySQL database results using a combination of HTML and CSS. My goal is to have all the "hi's" displayed under the column labeled "Good Comment," while the "asasd" and 4 occurrences of "BAD" shoul ...

I'm having trouble accessing the data stored in req.user within the user controller, despite having integrated it into the user isLoggedIn middleware

I am encountering an issue where I cannot access my req.user in the usercontroller, even though I have implemented it in the usermiddleware. Both storing data in req.user and retrieving data using req.user from the middleware to my controller are not work ...

Trouble with serving CSS files using Express static directory

In my app.js file, I have the following code: app.use(express.static(path.join(__dirname, '../public'))); This code snippet is from my main layout page: <link rel="stylesheet" href="/css/styles.css"> Despite trying various combinations, ...

Showing arbitrary text on Vue.js template

In my Vue.js application, I have a Loader component that randomly displays one of several messages. Here is how I implemented it: Vue.component('Loader', { data() { const textEntries = [ 'Just a moment', ...

Navigate with ease using the Jquery tabbar feature

I am currently troubleshooting a jQuery tabbar navigation that is almost working as expected. Here are the issues I've encountered: 1. Upon page load, no article appears visible. 2. When I click on a different tabbar item after the initial selection, ...

When I click on my div, the color does not change as expected

Recently, I wrote a code snippet where there are 9 different div elements each assigned a ".spaces" class. The intention was to change the color of these divs upon clicking on them. However, I encountered an issue where only the first div changes its color ...

Arranging content in a horizontal row using div elements

My webpage features two div elements. One of the div represents header content, while the other div displays details content. I want both sets of content to be aligned side by side. Specifically, I need the details content to always appear on the right-han ...

Reference to jQuery selectors for hyperlinks

I have added new links to a website I am working on for a friend. I tried using the jQuery snippet that works for the navigation bars, but it doesn't seem to be functioning properly. My assumption is that I might not be selecting the elements correctl ...

Ways to emphasize the contrast between two texts using CSS

One method to highlight specific parts of text using CSS can be found in this script: span.highlight { background-color: #B4D5FF; } However, what if we want to highlight the differences between two strings? Take for example these two strings: this ...

Finding the position of a specific element in an array by searching through multiple object keys

Assuming I have a single key (for example, if I have the object.name = 'Sam') and I want to find the index using: var index = array.map(function(el) {return el.name}).indexOf('Sam'); I can retrieve the index of the array element with ...

Displaying iterative content using Vue.js from an array of items

Looking to style questions and answers differently when rendering them. The data structure is as follows: dialogTut:{ mainTab:{ q:"data with 42 people?", a:"hehe", q:"Are awesome people?", a:"sometimes", ...

Tips for hiding the overflow scrollbar on Microsoft Chrome when there is no content to scroll

Looking for a solution to hide scroll bars in Microsoft Chrome, but only when there is no content to scroll? The current div and styles always show the horizontal and vertical scroll bars, even when the height exceeds the content. <div style="backgroun ...