开发者

Change image source by hovering on a label

开发者 https://www.devze.com 2022-12-13 16:20 出处:网络
I have multiple labels on a bar my web page and I want when I hover on that label, image in other div should change ba开发者_运维百科sed on the label being hovered.

I have multiple labels on a bar my web page and I want when I hover on that label, image in other div should change ba开发者_运维百科sed on the label being hovered.

Any help would be highly appreciared.

  • Sjain


With jQuery, the popular javascript library, you could do it rather easily:

-- Sample HTML

<label class="target">Hover to Change</label> 
<img src="image001.gif" class="sourceImage" />

-- Corresponding jQuery

$("label.target").hover(
  function () {
    // mousing-over <label class="target"> changes img to 'image002.gif'
    $("img.sourceImage").attr("src", "image002.gif");
  },
  function () {
    // mousing-out <label class="target"> changes img to 'image001.gif'
    $("img.sourceImage").attr("src", "image001.gif");
  }
);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号