Targeting multiple elements with jQuery

后端 未结 5 2226
无人及你
无人及你 2021-02-06 04:34

I have been searching but have come up blank and i\'m wondering if I can use one jQuery statement to target multiple elements on a page. I have several identical buttons on a pa

5条回答
  •  甜味超标
    2021-02-06 05:20

    Ok I got this working! Thanks Cletus you sent me in the right direction... I had to use the children selector on this, then choose each child and change its individualy classes... Heres the code...

    $j(function (){  
    $j(".hoverBTN").hover( 
    function() { 
        $j(this).children('div:nth-child(1)').addClass("hoveroverL");
        $j(this).children('div:nth-child(2)').addClass("hoveroverM");
        $j(this).children('div:nth-child(3)').addClass("hoveroverR");
    }, function() {
        $j(this).children('div:nth-child(1)').removeClass("hoveroverL");
        $j(this).children('div:nth-child(2)').removeClass("hoveroverM");
        $j(this).children('div:nth-child(3)').removeClass("hoveroverR");
    });
    

    });

    Works perfectly this way. I wanted something compact and easily reuseable and i think this covers both. Thanks again everyone...

提交回复
热议问题