jQuery到目标CSS a:hover类 [英] jQuery to target CSS a:hover class

查看:169
本文介绍了jQuery到目标CSS a:hover类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里混淆。什么是更改下面的链接的悬停CSS的最好的方法,如何? toggle.Class? add.Class?我想在悬停时显示图像。我已经能够改变文本的颜色

Confused here. What's the best way to change the hover CSS of the link below, and how? toggle.Class? add.Class? I want to show an image on hover. I have been able to change the color of the text with

$("#menu-item-1099 a:contains('rss')").css("color", "#5d5d5d");

,但似乎无法定位到悬停类。

but can't seem to target the hover class.

<div id="access">
<div class="menu-header">
<ul id="menu-main-menu" class="menu">
<li id="menu-item-1099" class="menu-item menu-item-type-custom menu-item-1099">
<a href="http://mydomain.com/feed/">rss</a></li>


推荐答案

使用 .css ()在jQuery中,你实际上不是改变CSS文件/创建新的CSS规则。你只是添加CSS到特定元素的< c> style 属性(内联CSS)。

When you use .css() in jQuery, you're not actually changing the CSS file / creating new CSS rules. You're simply adding CSS to specific elements' style attribute (inline CSS).

t定位到悬停类 - 您必须在悬停时执行某项操作,并将其悬停在外面:

So, you can't "target the hover class" - you have to do something on hover in, and revert that on hover out:

$("#menu-item-1099 a:contains('rss')").hover(function() {
    // Hover in, show an img
    $(this).after("<img src='blah.jpg'>");
    // Or alternatively
    $(this).addClass("hasImage"); // Where there is a CSS rule for .hasImage
}, function () {
    // Hover out, remove the img
    $(this).next().remove();
    // Or alternatively
    $(this).removeClass("hasImage");
});

这篇关于jQuery到目标CSS a:hover类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆