如何选择此范围?

时间:2014-09-04 12:32:37

标签: javascript jquery html jquery-selectors

这是我想在jquery中选择的元素

.box3 span.info:before{
  content:"15 vacatures";
    margin:0;
    padding:0 0 28px 0;

    font-family: 'MaisonNeueMono';
    letter-spacing: normal;
    font-weight: normal;
    font-size: 12px;
    text-transform: uppercase;
    position:relative;
}

我尝试了这个,但它只是没有选择它,也不适用于只放“.info”: 那么如何选择这个元素呢?

$(".box3 span.info:before").hover(function(){
    $(".box3 h1").fadeOut();
});

4 个答案:

答案 0 :(得分:1)

删除:before,它只是css部分,它不是用元素渲染的,它只是用来在元素之前添加css。

你只需要写下这个:

$(".box3 span.info").hover(function(){
    $(".box3 h1").fadeOut();
});

答案 1 :(得分:1)

伪元素before不是选择器的一部分,只需将其保留:

$(".box3 span.info").hover(function(){
    $(".box3 h1").fadeOut();
});

此外,您可能希望将风格和风格分开。内容插入如下:

.box3 span.info {
    margin:0;
    padding:0 0 28px 0;

    font-family: 'MaisonNeueMono';
    letter-spacing: normal;
    font-weight: normal;
    font-size: 12px;
    text-transform: uppercase;
    position:relative;
}

.box3 span.info::before{ 
    content:"15 vacatures";
}

答案 2 :(得分:0)

这里不需要伪选择器。你需要使用:

$(".box3 span.info").hover(function(){
  $(this).closest('.box3').find('h1').fadeOut();
});

答案 3 :(得分:0)

你不能用jQuery选择伪元素,因为它们不是真正的DOM对象,因此在jQuery上下文中不存在。

那说不能用jQuery选择你的:before伪元素。

如果您需要更多解释搜索SO,例如: Selecting and manipulating CSS pseudo-elements such as ::before and ::after using jQuery

相关问题