简体   繁体   English

选择器jQuery

[英]Selector Jquery

Hello iam learning jquery and JavaScript and i have a bunch of divs and span inside them, all this div has the same class, and also the span all of them has the same class what i want is when i do mouse over on a div, change the color of the letters with the tag span inside that div. 你好,我在学习jquery和JavaScript,我有很多div并在其中跨度,所有这些div都具有相同的类,而且当我将鼠标悬停在div上时,它们的跨度都具有相同的类,使用该div内的标签span更改字母的颜色。 ill let you how i structured my cod and my jquery function. 生病的你让我如何构造我的鳕鱼和我的jQuery函数。 i would like to know how i can use selector to achieve this. 我想知道如何使用选择器来实现这一目标。

this is the jsFiddle: 这是jsFiddle:

$(".wrap-faq").on("mouseover", hoverFaq);

    function hoverFaq(){
        $(".wrap-faq .faq .txt-preg-faq").css("color", "white")
        $(this).addClass("over");
    }

$(".wrap-faq").on("mouseleave", unHoverFaq);

    function unHoverFaq(){
        $(this).removeClass("over");
    }

http://jsfiddle.net/xtatanx/jz73b/ http://jsfiddle.net/xtatanx/jz73b/

I think that you want a simple CSS hover: 我认为您想要一个简单的CSS悬停:

.faq {
    color: black;
}
.faq:hover {
    background: orange;
    color: white;
}

This http://jsfiddle.net/saYFz/ is what you want? 您想要的是这个http://jsfiddle.net/saYFz/吗?

This code will add a CSS class to div when you hover over it: 当您将鼠标悬停在div上时,此代码将向其添加CSS类:

$(".wrap-faq").on("hover",
    function(){
        // on over, add class "over"
        $(this).addClass("over");
    },
    function(){
        // on out, remove class
        $(this).removeClass("over");
    }
);

Use CSS for the span manipulation. 使用CSS进行跨度操作。 Like: 喜欢:

.over span {color:red;}

Edit: If you want to process the hover only at span, you can simply modify the selector to: 编辑:如果只想在跨度上处理悬停,则只需将选择器修改为:

$(".wrap-faq span")

I'm guessing this is more what you're wanting: 我猜这更是您想要的:

http://jsfiddle.net/jz73b/1/ http://jsfiddle.net/jz73b/1/

$(".contents-faq").on("mouseover", '.wrap-faq', function() {
    $(".wrap-faq .faq .txt-preg-faq").css("color", "white")
    $(this).addClass("over");
}).on("mouseleave", '.wrap-faq', function() {
    $(this).removeClass("over");
});

Just add this line in your hoverFaq function: 只需在您的hoverFaq函数中添加以下行:

$(this).find('span').css('color', 'white');

Here you have it working: http://jsfiddle.net/jz73b/2/ 在这里,您可以使用它: http : //jsfiddle.net/jz73b/2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM