Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
Make CSS Background disappear onclick with React

The style within the div creates a red box. Upon clicking I want to remove it. Have tried implementing state but it wasn't working.

import React, { Component } from "react";

class ClickMe extends Component {
  render() {
    return (
      <div>
        <h1>Disapearing Box</h1>
        <h3>Click the Box, I dare you</h3>
        <div
          style={{
            height: "400px",
            width: "400px",
            background: "#ef8989",
            margin: "auto",
          }}
        ></div>
      </div>
    );
  }
}
export default ClickMe;

    );
  }
}
export default ClickMe;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

try it:

import React, { useState } from "react";

const ClickMe =() => {
  const [active, setActive] = useState(false)

  return (
    <div onClick={() => setActive(!active)}>
      <h1>Disapearing Box</h1>
      <h3>Click the Box, I dare you</h3>
      <div
        style={{
          height: "400px",
          width: "400px",
          background: active ? "none" : "#ef8989",
          margin: "auto",
        }}
      ></div>
    </div>
  );
}

export default ClickMe;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!