开发者

Quick javascript hover question

开发者 https://www.devze.com 2023-03-07 07:43 出处:网络
I have a quick JavaScript question. I was wondering if there\'s a way to make a div called #post li span to show up (appear) when you hover over the div \"#post li\" ? It\'d mean a lot if someone 开发

I have a quick JavaScript question. I was wondering if there's a way to make a div called #post li span to show up (appear) when you hover over the div "#post li" ? It'd mean a lot if someone 开发者_JAVA百科could provide me with a code.


You can do that directly with CSS:

#post li span {
    display: none;
}

#post li:hover span {
    display: inline;
}

If you want to use JavaScript and have jQuery, you can use:

$('#post li span').hide();
$('#post li').hover(
    function() { $('span', $(this)).show(); },
    function() { $('span', $(this)).hide(); }
);

If you want to use JavaScript and don't have jQuery, things start getting more complicated.


In older IE's you won't have access to the :hover pseudo class on none anchor tags. so you can use javascript like this:

$('#post li').hover(function() {
    $(this).find('span').show();
  },
  function() {
    $(this).find('span').hide();
  }
);

check out jQuery hover for more info on how it works


You can use CSS.
Apply display: none to #post li span, then add display:block for #post li:hover span

0

精彩评论

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