:has()jQuery无法正常工作 [英] :has() jquery is not working correctly

查看:91
本文介绍了:has()jQuery无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的网站上执行以下操作:

I'm trying to do something like below on my website:

$(".post-index:has(.wp-post-image)").css("background", "#000");

Js小提琴示例运行良好: http://jsfiddle.net/rami2929/4x4t9/

Js fiddle Example is working perfectly: http://jsfiddle.net/rami2929/4x4t9/

但这在我的演示网站上不起作用:

But it'a not working on my demo website:

我想更改具有图像的背景色框.如何在演示站点上实现此目的?

I would like to change box of background color that has image. How can I implement this on my demo site?

任何建议将不胜感激.

谢谢.

推荐答案

它在DOM ready函数之外,请进行以下更改:

It's outside the DOM ready function, change this :

$(function(){  
     $(".articleBox").click(function(){
         window.location=$(this).find("a").attr("href");  
         return false;  
    });

<!-- div mouseover change h2 color -->
    $('.articleBox').mouseover(function(){
        var color = $(this).find("a, .text-h2").css("color");
        $(this).find("a, .text-h2").css("color", "rgba(255, 156, 0, 0.8)");
        $(this).mouseout(function(){
            $(this).find("a, .text-h2").css("color", "rgb(51, 51, 51)");
        });
    });

});  

<!-- non image div change background color -->
$(".post-index:has(.wp-post-image)").css("background", "#000");

$(function(){  
     $(".articleBox").click(function(){
         window.location=$(this).find("a").attr("href");  
         return false;  
    });

    <!-- div mouseover change h2 color -->
    $('.articleBox').mouseover(function(){
        var color = $(this).find("a, .text-h2").css("color");
        $(this).find("a, .text-h2").css("color", "rgba(255, 156, 0, 0.8)");
        $(this).mouseout(function(){
            $(this).find("a, .text-h2").css("color", "rgb(51, 51, 51)");
        });
    });

    <!-- non image div change background color -->
    $(".post-index:has(.wp-post-image)").css("background", "#000");
});  

这篇关于:has()jQuery无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆