JavaScript javascript: mouse hover for background coloring and opacity javascript mouseover event,javascript mouseover mouseout,javascript mouseover tooltip,javascript

since yesterday i started javascript to make a hovering effect that applys to the body of the page(i want to change the background color of the body of the page while hovering a div),

I've watched some tutorials and i tried it myself but i ended up failing, I would like to know how can create this effect with javascript , i used something like this.

function mouseOver() {
  document.getElementsByClassName("body").style.backgroundColor = "black"
}

function mouseOut() {
  document.getElementsByClassName("body").style.backgroundColor = "white"
}
.college .image {
  left: 100px;
  top: 475px;
  position: absolute
}

.college:hover .imagefirst {
  opacity: 0.2;
}

.college .imagesecond {
  width: 550px;
  height: 900px;
  transform: translate(-110px, 500px);
  transition: transform 0.5s ease-in-out 0.25s;
  border-radius: 8px;
  overflow: hidden;
}

.college:hover>.imagesecond {
  transform: translate(-110px, -500px);
}

.college:hover>body {
  background-color: black
}

.lycee .image {
  left: 700px;
  top: 500px;
  position: absolute
}

.lycee .imagefourth {
  width: 537px;
  height: 600px;
  transform: translate(-160px, 500px);
  transition: transform 0.5s ease-in-out 0.2s;
  border-radius: 8px;
  overflow: hidden;
}

.lycee:hover>.imagefourth {
  transform: translate(-160px, -325px);
}

.formations .image {
  left: 1250px;
  top: 510px;
  position: absolute;
}

.formations .imagesixth {
  width: 550px;
  height: 900px;
  transform: translate(-100px, 400px);
  transition: transform 0.5s ease-in-out 0.2s;
  border-radius: 8px;
  overflow: hidden
}

.formations:hover>.imagesixth {
  transform: translate(-173px, -600px);
}

body {
  background: url("accueil.png") 33em 0% fixed no-repeat;
  position: fixed;
  background-color: white/* rgb(0,85,170); */
}
<!doctype html>
<html>

<head>
  <meta charset="utf-8" />
  <link rel="stylesheet" target='_blank' href="css.css" />

  <title> sainte marie </title>

</head>

<body>
  <div class="saintemarie">
    <a target='_blank' href="college/collegesaintemarie.html">
      <div onmouseover="mouseover()" onmouseout="mouseout()" class="college">
        <img class="image imagefirst" src="http://via.placeholder.com/196x175" />
        <img class="image imagesecond" src="http://via.placeholder.com/320x440" />
      </div>
    </a>

    <a target='_blank' href="lycee/lyceesaintemarie.html">
      <div class="lycee">
        <img class="image imagethird" src="http://via.placeholder.com/183x140" />
        <img class="image imagefourth" src="http://via.placeholder.com/320x440" />
      </div>
    </a>

    <a target='_blank' href="c&formation/c&fsaintemarie.html">
      <div class="formations">
        <img class="image imagefifth" src="http://via.placeholder.com/172x153" />
        <img class="image imagesixth" src="http://via.placeholder.com/320x440" />
      </div>
    </a>
  </div>


</body>

</html>
Answer:1

Make sure that your Javascript code loads after the content and replace onmouseOver with onmouseover.

Instead of document.getElementsByClassName("body").style.backgroundColor = "black" you can do this document.body.style.backgroundColor = 'red';

if you want to play with th e DIV's

var divs = document.getElementsByTagName('div');
for(var i=0; i < divs.length; i++) {
  divs[i].style.opacity = "0.8";
}

if you want to change the styles only of specific element with className

var divs = document.getElementsByClassName('classNameHere');
for(var i=0; i < divs.length; i++) {
  divs[i].style.opacity = "0.8";
}

Edited!

Answer:2

Body is not a class so this statement will not work, document.getElementsByClassName("body").style.backgroundColor = "black"

To Select Body you can use document.body or document.getElementsByTagName('body')[0];

function mouseOver() {
  document.body.style.backgroundColor = "black"
}

function mouseOut() {
  document.body.style.backgroundColor = "white"
}
.college .image {
  left: 100px;
  top: 475px;
  position: absolute
}

.college:hover .imagefirst {
  opacity: 0.2;
}

.college .imagesecond {
  width: 550px;
  height: 900px;
  transform: translate(-110px, 500px);
  transition: transform 0.5s ease-in-out 0.25s;
  border-radius: 8px;
  overflow: hidden;
}

.college:hover>.imagesecond {
  transform: translate(-110px, -500px);
}

.college:hover>body {
  background-color: black
}

.lycee .image {
  left: 700px;
  top: 500px;
  position: absolute
}

.lycee .imagefourth {
  width: 537px;
  height: 600px;
  transform: translate(-160px, 500px);
  transition: transform 0.5s ease-in-out 0.2s;
  border-radius: 8px;
  overflow: hidden;
}

.lycee:hover>.imagefourth {
  transform: translate(-160px, -325px);
}

.formations .image {
  left: 1250px;
  top: 510px;
  position: absolute;
}

.formations .imagesixth {
  width: 550px;
  height: 900px;
  transform: translate(-100px, 400px);
  transition: transform 0.5s ease-in-out 0.2s;
  border-radius: 8px;
  overflow: hidden
}

.formations:hover>.imagesixth {
  transform: translate(-173px, -600px);
}

body {
  background: url("accueil.png") 33em 0% fixed no-repeat;
  position: fixed;
  background-color: white/* rgb(0,85,170); */
}
<!doctype html>
<html>

<head>
  <meta charset="utf-8" />
  <link rel="stylesheet" target='_blank' href="css.css" />

  <title> sainte marie </title>

</head>

<body>
  <div class="saintemarie">
    <a target='_blank' href="college/collegesaintemarie.html">
      <div onmouseOver="mouseOver()" onmouseout="mouseOut()" class="college">
        <img class="image imagefirst" src="http://via.placeholder.com/196x175" />
        <img class="image imagesecond" src="http://via.placeholder.com/320x440" />
      </div>
    </a>

    <a target='_blank' href="lycee/lyceesaintemarie.html">
      <div class="lycee">
        <img class="image imagethird" src="http://via.placeholder.com/183x140" />
        <img class="image imagefourth" src="http://via.placeholder.com/320x440" />
      </div>
    </a>

    <a target='_blank' href="c&formation/c&fsaintemarie.html">
      <div class="formations">
        <img class="image imagefifth" src="http://via.placeholder.com/172x153" />
        <img class="image imagesixth" src="http://via.placeholder.com/320x440" />
      </div>
    </a>
  </div>


</body>

</html>
Answer:3

Something like this?

function mouseOver() {
  document.body.style.backgroundColor = "black"
}

function mouseOut() {
  document.body.style.backgroundColor = "white"
}
.college{
  height: 100px;
  width: 100px;
  border: 1px solid black;
}

.college .image {
  left: 100px;
  top: 475px;
  position: absolute
}

.college:hover .imagefirst {
  opacity: 0.2;
}

.college .imagesecond {
  width: 550px;
  height: 900px;
  transform: translate(-110px, 500px);
  transition: transform 0.5s ease-in-out 0.25s;
  border-radius: 8px;
  overflow: hidden;
}

.college:hover>.imagesecond {
  transform: translate(-110px, -500px);
}

.college:hover>body {
  background-color: black
}

.lycee .image {
  left: 700px;
  top: 500px;
  position: absolute
}

.lycee .imagefourth {
  width: 537px;
  height: 600px;
  transform: translate(-160px, 500px);
  transition: transform 0.5s ease-in-out 0.2s;
  border-radius: 8px;
  overflow: hidden;
}

.lycee:hover>.imagefourth {
  transform: translate(-160px, -325px);
}

.formations .image {
  left: 1250px;
  top: 510px;
  position: absolute;
}

.formations .imagesixth {
  width: 550px;
  height: 900px;
  transform: translate(-100px, 400px);
  transition: transform 0.5s ease-in-out 0.2s;
  border-radius: 8px;
  overflow: hidden
}

.formations:hover>.imagesixth {
  transform: translate(-173px, -600px);
}

body {
  background: url("accueil.png") 33em 0% fixed no-repeat;
  position: fixed;
  background-color: white/* rgb(0,85,170); */
}
<!doctype html>
<html>

<head>
  <meta charset="utf-8" />
  <link rel="stylesheet" target='_blank' href="css.css" />

  <title> sainte marie </title>

</head>

<body>
  <div class="saintemarie">
    <a target='_blank' href="college/collegesaintemarie.html">
      <div onmouseover="mouseOver();" onmouseout="mouseOut();" class="college">
        <img class="image imagefirst" src="http://via.placeholder.com/196x175" />
        <img class="image imagesecond" src="http://via.placeholder.com/320x440" />
      </div>
    </a>

    <a target='_blank' href="lycee/lyceesaintemarie.html">
      <div class="lycee">
        <img class="image imagethird" src="http://via.placeholder.com/183x140" />
        <img class="image imagefourth" src="http://via.placeholder.com/320x440" />
      </div>
    </a>

    <a target='_blank' href="c&formation/c&fsaintemarie.html">
      <div class="formations">
        <img class="image imagefifth" src="http://via.placeholder.com/172x153" />
        <img class="image imagesixth" src="http://via.placeholder.com/320x440" />
      </div>
    </a>
  </div>


</body>

</html>
Answer:4

good going! but small mistake of uppercase and lowercase letters

1)

please see your function name carefully 
<div onmouseover="mouseover()" onmouseout="mouseout()" class="college">

'O' should be capital as you defined it mouseOver() and mouseOut();

2)

for using byName you must have tag with that name so for using 
document.getElementsByClassName("body").style.backgroundColor = "black";
add name="body" in <body>  
for example <body name="body">

or

  simply use byTagName atribute like this
document.getElementsByTagName("body")[0].style.backgroundColor = "black";

happy coding, :-)

Answer:5

Consider the following piece of code: function A() { for(i = 0; i < 3; i++) { console.log("---" + i + "---"); B(); } } function B() { for(i = 0; i < 3; i++) ...

Consider the following piece of code: function A() { for(i = 0; i < 3; i++) { console.log("---" + i + "---"); B(); } } function B() { for(i = 0; i < 3; i++) ...

  1. javascript loop through array
  2. javascript loop through object
  3. javascript loop array
  4. javascript loop over array
  5. javascript loop through json
  6. javascript loop through object properties
  7. javascript loop through string
  8. javascript loop through map
  9. javascript loop through dictionary
  10. javascript loop through json object
  11. javascript loop continue
  12. javascript loop through array of objects
  13. javascript loop n times
  14. javascript loop through select options
  15. javascript loop through table rows
  16. javascript loop through elements
  17. javascript loop x times
  18. javascript loop through htmlcollection
  19. javascript loop through child elements
  20. javascript loop through associative array

I have a clickable table row and checkbox in that row. When user click on that row, user will be redirected to other page. That was expected behavior. Now the problem is when user click on checkbox, ...

I have a clickable table row and checkbox in that row. When user click on that row, user will be redirected to other page. That was expected behavior. Now the problem is when user click on checkbox, ...

I am new to javascript, The below question should return 1 according to my knowledge about javascript, but it's returning "undefined". could anyone tell me why it's not returning 1? var foo = { ...

I am new to javascript, The below question should return 1 according to my knowledge about javascript, but it's returning "undefined". could anyone tell me why it's not returning 1? var foo = { ...

I got an interface,,already logged in with a new username now i want so select this user to my selected option value and insert it into Mysql DB.. <option value="" required="required"> Please ...

I got an interface,,already logged in with a new username now i want so select this user to my selected option value and insert it into Mysql DB.. <option value="" required="required"> Please ...

  1. select current logged in user oracle
  2. sql select current logged in user