Change() inside each() jQuery

前端 未结 4 2111
抹茶落季
抹茶落季 2020-12-18 06:36

What is the best way to manage this kind of situation :

$(\'.element\').each(function() {

    $sibling = // find a sibling to $this.
    $mainElement = $(         


        
4条回答
  •  春和景丽
    2020-12-18 07:28

    I'd say the easiest bet for you is to use an .each on the siblings, and then finding the relative ".element" for the sibling. Depends on your code of course. Otherwise, something like this might work, even though it feels a bit redundant due to the .each:

    $('.element').each(function() {
        $(this).siblings('.sibling').change(function() {
            var mainElement = $(this).siblings('.element');
            // Do whatever you want here...
        });
    });
    

提交回复
热议问题