简体   繁体   English

jQuery通过ID选择器更改CSS

[英]jquery change css via id selector

ı want to change a specific style of div by its id. 我想通过其ID更改div的特定样式。 However, it seems it is not working at all. 但是,它似乎根本不起作用。 The necessary codes are below: 必要的代码如下:

Jquery: jQuery:

$(document).ready(function () {

$(".a_10.08.201223:56:49").hover(function(){
        $("#10.08.201223:56:49").removeClass('arrow-up').addClass('arrow-up2');

    }).mouseout(function(){
        $("#10.08.201223:56:49").removeClass('arrow-up2').addClass('arrow-up2');        
    });
});

HTML: HTML:

    <div class = "a_10.08.201223:56:49">

    Something in here

        <div class="arrow-up" id="10.08.201223:56:49"></div>
</div>

The idea is that this ids are the date of the comments. 想法是此id是评论的日期。 For instance, 10.08.201223:56:49 id a date for a specific comment and a_10.08.201223:56:49 class represents the area to be triggered. 例如,10.08.201223:56:49标识特定注释的日期,而a_10.08.201223:56:49类表示要触发的区域。 When it is hovered through the upper div, the child div(arrow) will be displayed. 将其悬停在上div时,将显示子div(箭头)。 When mouse is out of the upper div, the arrow will be disappered. 当鼠标移出上方div时,箭头将消失。 It seems that i could not do it so far. 看来到目前为止我还做不到。 Thanks 谢谢

You have to escape special character used in jquery selector eg : , . 您必须转义jquery选择器中使用的特殊字符,例如:. etc. 等等

Live Demo 现场演示

$(document).ready(function () {

$(".a_10\\.08\\.201223\\:56\\:49").hover(function(){

        $("#10\\.08\\.201223\\:56\\:49").removeClass('arrow-up').addClass('arrow-up2');

    }).mouseout(function(){
        $("#10\\.08\\.201223\\:56\\:49").removeClass('arrow-up2').addClass('arrow-up2');        
    });
});​

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

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