Applying a blur effect using CSS to all divs underneath

I have multiple divs and would like to apply a blur effect to all of them simultaneously. However, currently only the first div with the blur effect class is affected by the blur.

When I click the button, I want the text "hello world" to become blurred. Unfortunately, when I press the button, the text remains unchanged.

function addBlur() {
  var overlay = document.getElementsByClassName("overlay");
  var blurDiv = document.getElementsByClassName("blur");
  if ((overlay[0].style.display === "none") && (blurDiv[0].style.display === "none")) {
    overlay[0].style.display = "block";
    blurDiv[0].style.display = "block";
  } else {
    overlay[0].style.display = "none";
    blurDiv[0].style.display = "none";
  }
}
body {
  background-color: white;
  text-align: center;
  color: black;
  font-family: Arial, Helvetica, sans-serif;
  width: 800px;
  height: 600px;
}

.blur {
  display: none;
  position: absolute;
  width: 800px;
  height: 600px;
  background-color: rgba(44, 44, 27, 0.527);
  filter: blur(8px);
  z-index: 1;
}

.text {
  position: absolute;
  top: 82%;
  left: 25%;
  right: 25%;
  z-index: 1;
}

.overlay {
  position: absolute;
  display: none;
  width: 35%;
  height: 42%;
  top: 28%;
  left: 25%;
  right: 25%;
  bottom: 20%;
  background-color: #ffb87d;
  z-index: 2;
  cursor: pointer;
}

.button {
  background-color: rgb(255, 127, 80);
  padding: 24px;
  color: rgb(255, 255, 255);
  border-radius: 15px 15px;
}

.touch {
  display: block;
  border: solid 4px;
  position: absolute;
  width: 800px;
  height: 600px;
  z-index: 2;
}
<!DOCTYPE html>
<html>

<head>

  <title>Page Title</title>

</head>

<body>

  <div class="touch">
    <div class="text">
      <H1> Hello world! </H1>
    </div>
    <!-- text -->
    <H3> touch </H3>
    <div>
      <button class='button' onclick='addBlur()'> Apply Blur </button>
    </div>
    <div class="overlay">
      <p> Prime number </p>
    </div>
    <!-- overlay -->
  </div>
  <!-- touch -->
  <div class="blur">
  </div>

</body>

</html>

Answer №1

My approach involved assigning an id to "Hello World" and creating a button that, when clicked, would blur the text. Clicking the button a second time would revert the text back to its original state.

function on() {
  var x = document.getElementsByClassName("overlay");
  var y = document.getElementsByClassName("blur");
  if ((x[0].style.display === "none") && (y[0].style.display === "none")) {
    x[0].style.display = "block";
    y[0].style.display = "block";
    document.getElementById("test").style.filter= "blur(8px)";
   
  } else {
    x[0].style.display = "none";
    y[0].style.display = "none";
    document.getElementById("test").style.filter= "blur(0px)";
  }
}
body {
  background-color: white;
  text-align: center;
  color: black;
  font-family: Arial, Helvetica, sans-serif;
  width: 800px;
  height: 600px;
}

.blur {
  display: none;
  position: absolute;
  width: 800px;
  height: 600px;
  background-color: rgba(44, 44, 27, 0.527);
  filter: blur(8px);
  z-index: 1;
}

.testo {
  position: absolute;
  top: 82%;
  left: 25%;
  right: 25%;
  z-index: 1;
}

.overlay {
  position: absolute;
  display: none;
  width: 35%;
  height: 42%;
  top: 28%;
  left: 25%;
  right: 25%;
  bottom: 20%;
  background-color: #ffb87d;
  z-index: 2;
  cursor: pointer;
}

.button {
  background-color: rgb(255, 127, 80);
  padding: 24px;
  color: rgb(255, 255, 255);
  border-radius: 15px 15px;
}

.tocco {
  display: block;
  border: solid 4px;
  position: absolute;
  width: 800px;
  height: 600px;
  z-index: 2;
}
<!DOCTYPE html>
<html>

<head>

  <title>Page Title</title>

</head>

<body>

  <div class="tocco">
    <div class="testo">
      <H1 id="test"> Hello world! </H1>
    </div>
    <!-- testo -->
    <H3> tocco </H3>
    <div>
      <button class='button' onclick='on()'> Lancia </button>
    </div>
    <div class="overlay">
      <p> Numero primo </p>
    </div>
    <!-- overlay -->
  </div>
  <!-- tocco -->
  <div class="blur">
  </div>

</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

How can I select elements in CSS that are "between x and y"?

If I have an HTML table with 20 rows and 3 columns (20x3), I am looking to highlight the rows from 7 to 12 in red. What CSS selector should I use for this specific task? How can I define the range of rows to be styled as "between"? ...

Searching for the closest jQuery value associated with a label input

As a beginner in JQuery, I am looking to locate an inputted value within multiple labels by using a Find button. Below is the HTML snippet. Check out the screenshot here. The JQuery code I've attempted doesn't seem to give me the desired output, ...

Displaying multiple categories of articles on a single page with Node.js

Seeking a solution to limit the number of posts displayed for each category using a .limit() function, but uncertain on how to proceed. Currently utilizing Mongoose and Express in my code setup. The existing code snippet is outlined below: router.get(&a ...

Error encountered when assigning a value to a session array in PHP 7.0

I am the author of this script <?php session_start(); if($_POST["num"] > $_SESSION["ratings"][$_POST["title"]]) $SESSION["ratings"][$_POST["title"]] = $_POST["num"]; ?> Although my syntax seems correct to me, the IDE is showin ...

Removing a background by linking a CSS file

Issue Resolved: I have found the solution. The problem was that the css document still contained html tags. Thank you to everyone who provided assistance. While designing a website using css, I encountered a situation where the site worked perfectly when ...

Fuzzy picture utilizing <canvas>

Working on translating a webgame from Flash to HTML5 with pixel art sprites, I've noticed that the canvas appears blurry compared to Flash where pixels are more defined. <!DOCTYPE html> <html> <body> <canvas id="c" style="bor ...

Is there a way to add a <video> tag in tinymce editor without it being switched to an <img /> tag?

I am attempting to include a <video> tag within the tinymce editor, but it keeps changing it to an <img> tag. Is there a way to prevent this conversion and keep the <video> tag intact? I want to enable videos to play inside tinymce whil ...

Ways to format the direct descendant of a multi-level list?

Check out my nested ul list: <ul> <li> <a href="/"></a> </li> <li> <a href="/"> </a> &l ...

Adjust the dimensions of the react-dropdown-tree-select element to better fit your needs

Hey there, I'm a beginner web developer currently working on a tree-based dropdown menu. Check out the documentation here To see it live in action, visit the example here I'm trying to adjust the height and width of the "Search/DropDown bar" in ...

Refresh the Page or URL After Submitting a Form using JavaScript or PHP

Just a heads up: I'm fairly new to the world of web development. Currently, I'm in the process of crafting an event calendar using CodeIgniter. However, I've hit a bit of a snag. Whenever I try to update an event using JavaScript, the page ...

What is the process for connecting an HTML page to a CSS file located in a parent directory?

Here's the problem I'm facing: I recently encountered some organizational issues with my website, so I decided to reorganize my files for better classification. The current folder structure looks like this: www resources images ... css de ...

Combine the initial element of one array with the initial element of another array in JavaScript

Is there a more efficient way to concatenate the first item of one array with the first item of another array in JavaScript, and automate console.log for each pair? Check out the code snippet below: $("button#search").on("click", function(){ var inputVa ...

how to toggle a pre-selected checkbox in a Vue component

https://i.stack.imgur.com/6GQl7.png When dealing with a tree view checkbox in Vue, I encountered an issue where editing data within a selected zone should automatically check the corresponding countries based on previous selections. The ID of the selected ...

Creating an autocomplete feature with Materialize.css that opens the list automatically without any minimum input length requirement

When using Materialize.css autocomplete, I am trying to make the list open upon focusing the textbox without entering any characters. I attempted to achieve this by setting {minLength: 0}: $('#dataset_input').autocomplete({data: res, limit: 20, ...

Can I display different text when blinking with Javascript?

I need to display text that changes every few seconds within a single div. var blink_speed = 1000; // every 1000 == 1 second, adjust to suit var t = setInterval(function () { var ele = document.getElementById('myBlinkin ...

Utilize jQuery to locate a specific value within a collapsible Bootstrap 4 table

Is it possible to use a Bootstrap 4 table inside a collapse? I need to search for a specific value in the table and if the value is found, I want to open the collapse and display the row containing that value. <div id="collapseStudents" class="collapse ...

Arrange the DIVs in the identical spot and switch them back and forth

I'm struggling with a dilemma involving two DIVs. I am looking to have two DIVs positioned in the exact same spot on the page and toggle between them. When one div disappears, the other should appear using jQuery toggle(). The challenge lies in havi ...

Instructions for positioning a 3d cube within another 3d cube with the help of three.js

I'm currently working on a project involving cargo management and I am looking to create a 3D image of the packing order. I am new to using THREE.js and need assistance in rendering the objects inside the container. While I have the positions (x, y, ...

What is the best way to display an icon and text side by side in the header of a Phonegap app

____________________________________________________________ | logo_image page_Title | ------------------------------------------------------------ I am looking to create a header for my PhoneGap app similar to the one sh ...

Combining a group of JavaScript objects

I am facing a challenge with my collection as I need to perform aggregation using only JavaScript. I have attempted various approaches utilizing the Lodash library but unfortunately, I have not been successful. If you could provide me with some guidance on ...