How to change content of div on hover using JQuery/Javascript

后端 未结 6 1139
醉酒成梦
醉酒成梦 2021-01-29 16:37

I\'m trying to change the contents of a div when it\'s hovered over using JQuery. I\'ve seen answers on stack overflow, but I can\'t seem to get it working.

I\'ve tried

6条回答
  •  既然无缘
    2021-01-29 16:55

    You can use jQuery's .hover() function along with the .text() function to do what you want. Also, no need for document.getElementById:

    $("#imgDiv").hover(
      function() {
        $("#titleDiv").text("hovering");
      },
      function() {
        $("#titleDiv").text('title');
      }
    );
    body {
      background: white;
      padding: 20px;
      font-family: Helvetica;
    }
    
    #imgDiv {
      width: 100px;
      height: 100px;
      background-color: pink;
    }
    
    
    title

提交回复
热议问题