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

206
Views
How can I make the text invisible when hovering over a tex and pressing the mouse button?

I'm new, tell me how to implement so that when you hover and click on the mouse button, the text should be made invisible. And when you click on the spacebar, it will be deleted from the page. Can this be done with just HTML and CSS? Or can it be implemented using JavaScript? Tell me how to do it better? Here is the code where I implemented the text change:

.body {
  background: #f1f1f1;
  font-family: tahoma;
}

.container {
  width: 600px;
  margin: 70px auto;
}

.block {
  padding: 40px;
  border: 1px solid #ddd;
  color: #666;
  background: #fff;
}

.eng {
  color: lime;
  font-family: sans-serif;
  display: none;
}

.container_1:hover .rus {
  display: none;
}

.container_1:hover .eng {
  display: block;
}
<div class="container">
  <div class="container_1">
    <div class="block rus">
      Junior Frontend Developer
    </div>
    <div class="block eng">
      Junior Frontend Developer
    </div>
  </div>
</div>

Now you need to do it on mouse click and space, but I don’t really understand how to implement it

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Well first, your current code for swapping the display of the message (while functional) is not really a good approach. Instead of having two pre-made versions of the text and then showing/hiding one vs. the other, just have the one element and change its style when needed.

As for making the element become hidden and then removed, see the following code with comments:

// Variable to store the last item that was clicked
let lastClicked = null;

// Set up a click event on the element
document.querySelector(".block.eng").addEventListener("click", function(evt){
  lastClicked = this; // Store a reference to what was just clicked
  this.classList.add("hidden"); // Add the CSS that hides the element
  
});

// Set up the spacebar press event
document.addEventListener("keypress", function(evt){
  if(evt.key === " "){       // Check for spacebar
    lastClicked.remove();    // Remove the element from the document
  }
});
.body {
    background: #f1f1f1;
    font-family: tahoma;
}

.container {
    width: 600px;
    margin: 70px auto;
}

.block {
    padding: 40px;
    border: 1px solid #ddd;
    color: #666;
    background: #fff;
}

.container_1:hover .eng{
    color: lime;
    font-family: sans-serif;
}

.hidden{
    opacity:0;
}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <link rel="stylesheet" href="style.css"type="text/css">
    </head>
    <body>
      <div class="container_1">       
        <div class="block eng">
            Junior Frontend Developer
        </div>test
      </div>
    </body>
</html>

about 4 years ago · Juan Pablo Isaza Report

0

If I understood what you needed done correctly. It can be done using some CSS and JS.

Here's a code snippet

$(".MagicElement").on("click", function (element) 
{
  $(this).toggleClass("hidden");
});

$('body').keyup(function(e){
   if(e.keyCode == 32){
       // user has pressed space
       $(".MagicElement:hover").remove();
   }
});
.MagicElement:active { opacity: 0; }
.hidden { opacity: 0; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class = 'MagicElement'>This is a block of text 1</div>
<div class = 'MagicElement'>This is a block of text 2</div>
<div class = 'MagicElement'>This is a block of text 3</div>
<div class = 'MagicElement'>This is a block of text 4</div>

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!