Skip to content Skip to sidebar Skip to footer

:has() Jquery Is Not Working Correctly

I'm trying to do something like below on my website: $('.post-index:has(.wp-post-image)').css('background', '#000'); Js fiddle Example is working perfectly: http://jsfiddle.net/ra

Solution 1:

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

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

<!-- 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");

to

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

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

Post a Comment for ":has() Jquery Is Not Working Correctly"