简体   繁体   English

jQuery选择器

[英]jquery selectors

I need to select a class in my javascript and change one of its property. 我需要在JavaScript中选择一个类并更改其属性之一。 but since that class is being used with different divs, I need to change the property of the class I hover upon only and not the other ones. 但是由于该类正与不同的div一起使用,因此我需要更改仅悬停在其上的类的属性,而不更改其他悬停的类。 is that possible? 那可能吗?

the html structure looks like this: html结构如下所示:

<div class="home_linkbox_href"><a href=""><div class="home_linkbox">
                    <h1>/h1>
                    <h2></h2>
                </div></a></div>

the javascript: javascript:

$(".home_linkbox_href a").hover(function(){
    //alert("u did it...");
    $(".home_linkbox_href a .home_linkbox").css("background-color", "#ffe500");

    },
    function(){
        $(".home_linkbox").css("background-color", "#000");
});

can someone help? 有人可以帮忙吗?

I think you would use $(this). 我认为您会使用$(this)。

$(".home_linkbox_href a").hover(function(){
    $(this).css("background-color", "#ffe500");
    $(this).attr("href", "http://www.google.com");
    },
    function(){
        $(this).css("background-color", "#000");
});

You can specify this as the context for the selector, which will find matches only in the currently hovered element: 您可以指定this作为选择,它会发现只有在当前徘徊元素匹配的情况下:

$(".home_linkbox_href a").hover(function(){
    //alert("u did it...");
    $(".home_linkbox", this).css("background-color", "#ffe500");

    },
    function(){
        $(".home_linkbox", this).css("background-color", "#000");
});
$(".home_linkbox_href").find("a").hover(
  function(){
    $(this).siblings(".home_linkbox").css("background-color", "#ffe500");
  },

  function(){
    $(this).siblings(".home_linkbox").css("background-color", "#000");
  }
);

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

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