gpt4 book ai didi

javascript - :has() jquery is not working correctly

转载 作者:行者123 更新时间:2023-11-28 20:27:40 25 4
gpt4 key购买 nike

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

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

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

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

我想更改带有图像的背景颜色框。如何在我的演示网站上实现此功能?

如有任何建议,我们将不胜感激。

谢谢。

最佳答案

它在 DOM 就绪函数之外,请更改它:

$(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");
});

关于javascript - :has() jquery is not working correctly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17073552/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com