Select first and last element with particular class using jQuery

前端 未结 4 1193
执笔经年
执笔经年 2020-12-16 10:08

I have a list of spans with particular class \"place\" and some of them have class \"activated\". Is there a way to select the first item with class \"activated\" and the la

4条回答
  •  佛祖请我去吃肉
    2020-12-16 10:42

    var firstspan = $('span.activated:first'),
        lastspan = $('span.activated:last');
    

    By the way, if you're using jQuery, what's with all the inline click events?

    You could add some code like so:

    $('span.place').click(function() {
        activate(); // you can add `this` as a parameter
                    // to activate if you need scope.
    });
    

提交回复
热议问题