简体   繁体   English

React.js应用程序中的jQuery风格的悬浮CSS样式

[英]jQuery-style hover CSS styling in React.js app

I have a React.js app that adds items to a list. 我有一个React.js应用程序,可将项目添加到列表中。 In my index.html file, I am using jQuery to facilitate hovering over certain elements leading to changing the style on other elements. 在我的index.html文件中,我使用jQuery来帮助将鼠标悬停在某些元素上,从而改变其他元素的样式。 However, after new items are added, jQuery seems not to recognize them. 但是,添加新项目后,jQuery似乎无法识别它们。

$(".list-item").hover(function(){
    $(this).css("border", "1px solid #000");
    $("."+this.childNodes[0].classList[0]+" .item").css("display", "block");
    $("h2."+this.childNodes[0].classList[0]).css({"color":"#555"});
}, function(){
     ...
})

This works for list items that are present when the app is loaded, but not for elements added later by the user. 这适用于加载应用程序时出现的列表项,但不适用于用户以后添加的元素。 Is there a way to make jQuery recognize the new elements, or is there a better method using only CSS or React? 有没有办法让jQuery识别新元素,还是有一种仅使用CSS或React的更好的方法?

Use the :hover CSS pseudo class. 使用:hover CSS伪类。 Don't do it with jQuery. 不要使用jQuery。

.list-item:hover
    border: 1px solid #000
    ...

    h2
    .other-class
    .etc

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

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