jquery 选择多级父子元素

     <div class="box">
            <div class="item">
                    <div class="out">
                        <div class="inside">
                                666
                        </div>
                    </div>
            </div>
        </div>
        <script>
            var one = $('.box').children().attr('class'); //item
            var two = $('.box').children().find('.out').attr('class');//out
            var three = $('.inside').parent().attr('class'); //out
            var four = $('.inside').parents('.item').attr('class') //item
        </script>

 

1.选择直接父子元素:

  $(e).parent();

       $(e)children()

2.选择多级父子元素:

 父:$(e).parents('.box');

子:$(e).children().find('.inside');

3.jquery 对象转 dom

  $(e).get(0);

posted @ 2019-08-29 14:33  william_new  阅读(3498)  评论(0编辑  收藏  举报