changing the image when hovering over the div

Good time of day I have a div with the test class and when you hover over the div you need to change the image I tried to write in jquery but I can't understand where the error is

if ($(".test") hover(handlerInOut(eventObject))){
  $(".test").attr("src", "img/Vector4.png");

}

Author: Міша Корольков, 2019-09-18

1 answers

If is not needed. Plus, the syntax is broken. You should have something like this.

$(".test").hover(function(){
  $(this).find('img').attr("src", "img/Vector4.png");
})

The meaning is this: when you hover the pointer over an element with the "test" class, an event handler function is launched that will replace the child element 'img' attribute src.

 0
Author: RainNoise, 2019-09-18 13:41:44