Unable to see the cursor pointer in CSS

I have gone through all the previous discussions, but I am still unable to solve this issue. When I hover over a button with the cursor set to pointer, it does not work as expected. Additionally, the hover effect is also not functioning properly. I have included all of my code below, including the JavaScript. I am not sure if the problem lies within the JavaScript, but I highly doubt it.

const colorBtn = document.querySelector('.colorBtn');
const bodyBcg = document.querySelector('body');

const colors = [
  '#6C5B7B',
  '#C06C84',
  '#F67280',
  '#F8B195',
  '#EC2049',
  'A7226E',
  '45ADA8'
];

//add event listener

colorBtn.addEventListener('click', changeColor);

function changeColor() {
  // bodyBcg.style.backgroundColor = colors[2];

  //get random number, Math.floor gives you a number between 0 and 0.9999... so we round down and times by the length of the array
  let random = Math.floor(Math.random() * colors.length);
  bodyBcg.style.backgroundColor = colors[random];
}
body {
 min-height: 100vh;
 display: flex;
 justify-content: center;
 align-items: center;
}

.colorBtn {
 padding: 0.25rem 0.5rem;
 border: 3px solid #fefefe;
 border-radius: 7px;
 color: #fefefe;
 background: rgba(0, 0, 0, 0.6);
 font-size: 1.5rem;
 text-transform: capitalize;
 cursor: pointer;
 outline: none;
}

.colorBtn:hover {
 background: rgb(0, 0, 0);
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <link rel="stylesheet" href="/main.css" />
  </head>
  <body>
    <button type="button" class="colorBtn">Press to change color</button>
    <script src="/script.js"></script>
  </body>
</html>

Answer №1

Two instances of the .colorBtn class were found in the css file. The issue should be resolved by removing the extra one.

Answer №2

Do you ever find yourself wondering why the color doesn't always change when you click the button? To troubleshoot this issue, try adding a line of code console.log(random); like the example below. Sometimes, it may seem like the color hasn't changed, but in reality, it has randomly selected the same color as before, giving the illusion that it's not working properly. Rest assured, the code is functioning perfectly.

const colorBtn = document.querySelector('.colorBtn');
const bodyBcg = document.querySelector('body');

const colors = [
  '#6C5B7B',
  '#C06C84',
  '#F67280',
  '#F8B195',
  '#EC2049',
  'A7226E',
  '45ADA8'
];

//add event listener

colorBtn.addEventListener('click', changeColor);

function changeColor() {

  // bodyBcg.style.backgroundColor = colors[2];

  //get random number, Math.floor gives you a number between 0 and 0.9999... so we round down and times by the length of the array
  let random = Math.floor(Math.random() * colors.length);
  console.log(random);
  bodyBcg.style.backgroundColor = colors[random];
}
body {
 min-height: 100vh;
 display: flex;
 justify-content: center;
 align-items: center;
}

.colorBtn {
 padding: 0.25rem 0.5rem;
 border: 3px solid #fefefe;
 border-radius: 7px;
 color: #fefefe;
 background: rgba(0, 0, 0, 0.6);
 font-size: 1.5rem;
 text-transform: capitalize;
 cursor: pointer;
 outline: none;
}

.colorBtn:hover {
 background: rgb(0, 0, 0);
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <link rel="stylesheet" href="/main.css" />
  </head>
  <body>
    <button type="button" class="colorBtn">Press to change color</button>
    <script src="/script.js"></script>
  </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

IE compatibility mode causing ckeditor dropdown to be hidden

When using the CKEditor editor bar inside a green div with another div below it, I noticed that when clicking on "font" or any other option that opens a dropdown menu, it gets hidden behind the bottom div. This issue seems to occur in browsers like Chrome ...

Building a unique mobile number input box with country code in HTML

Struggling to design a unique mobile input box that separates the mobile number and country code with a divider. Need some assistance in creating this custom input field. Design https://i.sstatic.net/M0Wvs.png Current Implementation <div cla ...

The issue with CSS Width:100% not functioning properly in Google Chrome

I am currently working on creating a gallery section that includes captions using the figure and figcaption elements. This gallery must be responsive and adapt to varying heights and widths along with their corresponding captions. While everything is func ...

How to incorporate a background image into a hyperlink?

I am working on a class that I have created, which is called .blueButton. It contains some CSS styling that makes it look like a button. .blueButton { /* Styling properties go here */ } To implement this button, I use the following HTML code: <a ...

Moving your cursor over the text will eliminate the border of the <img> located directly above it

Check out the latest products here! <ul class="products"> <li class="product first"> <a href="http://www.gwendolynbarnes.com/product/finis/"> <img width="117" height="150" src="http://www.gwendolynbarnes.co ...

The functionality of the Bootstrap tabbed pane is not functioning correctly

I am currently in the process of creating a modal tabbed pane in bootstrap following the instructions provided in this guide. You can view the code and functionality on this fiddle. $(document).on("click","#tabs a",function(event) { alert("!!!"); ...

Having trouble getting jQuery css() function to work properly?

<a href="https://www.timeatthebar.co.uk" target="_blank"><img id="icon-img" src="assets/img/tabicon2.png" class="position-absolute top-50 start-50 translate-middle" style="max-width:113px; top ...

What is the best way to reposition my boxes to sit below the diamond DIV instead of behind it?

I've been learning HTML5 and CSS, but I'm encountering an issue where the divs are appearing behind other divs. My goal is to have diamonds separated by boxes, with the boxes displayed below the diamonds. Clicking on a diamond should jump to the ...

Aligning a rotated paragraph in the middle of its parent container

Here is my current progress: http://jsfiddle.net/2Zrx7/2/ .events{ height:100px; position: relative; } .tt_username{ position: absolute; top:0px; height: 100%; width: 30px; background: #ccc; text-align: center; } .tt_usern ...

When I click on the icon, I wish for it to revert back to its original state by spinning

Is there a way to revert the icons back to their original state when clicked again, without losing any of the current functionalities? When an icon is clicked for the first time, it rotates 180 degrees. The icon rotates back if another icon is clicke ...

Ways to eliminate the excess space surrounding an Image border

I am looking to position the image at the top right corner of the screen. body{ font-family: 'Roboto', sans-serif; font-weight: 300; background: #822B2B; color: #ffffff; overflow: hidden; } #showcase{ display: flex; justify-content: center; al ...

Tips for achieving fluid and seamless page scrolling on a website

Looking to add smooth scrolling to my website but unsure of the best method - whether to override normal mouse scrolling or pursue another approach. I'm aiming for a similar effect as seen here. Give it a try and scroll through the page. ...

Prevent scrolling while popup is open

I found a helpful tutorial online for creating a jQuery popup (). However, due to my limited understanding of jQuery, I'm having trouble getting it to meet my needs. The issues I'm facing are: I need to prevent the webpage from scrolling when ...

Challenges encountered on Chrome browser when using label:hover along with relative positioning

Currently, I am in the process of creating a price list for a section of a website I'm developing. To make it interactive, I am utilizing checkbox type inputs along with labels so that users can select the services they desire, and the webpage will au ...

Looking to subtly transition from the current webpage to the next one with a fading effect?

I'm looking to create a smooth transition between web pages on my site by slowly fading out the current page and fading in the next one when a link is clicked. $(document).ready(function() { $('body').css("display","none"); $(&a ...

collapsed icon sliding over navigation slider in mobile Bootstrap 4

<nav class="navbar navbar-toggleable-lg navbar-light bg-faded justify- content-center"> <div class="container "> <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarText" aria- ...

When using CSS @media print with inches, different dimensions are displayed post-printing

I'm currently working on a project that involves printing a single div from my webpage. However, I've encountered some issues with the @page tag not affecting the print output as expected. I attempted to manually set the dimensions of the element ...

Steps for adjusting the margin of a section using the p tag

Newbie CSS inquiry here... Here's what I currently have in my stylesheet: #topheader { position: absolute; width: 100%; height: 100px; background-color: #D1E6DA; font-size: 200%; } I want to include the following: p { margi ...

When the checkbox is not selected, the content on the page will revert back to its original state

Is there a way to dynamically change content on a page when a checkbox is checked, and revert it back when the checkbox is unchecked? I don't want to manually set each element's value to default in JavaScript and CSS. <div class="switch&q ...

How can I create a responsive design for my div elements?

I am facing an issue with responsiveness in my div container. Inside the square-shaped frame, I have a h2 tag that does not adjust properly when viewed on different devices such as mobile and browsers. Despite setting up media queries to make it responsive ...