...">

How javascript "this" handles multiple selector returns from jquery?

I was making a menu today, and I stumbled on this curious case, with the following HTML:
  • 1
  • 2 - Here is a Submenu
    • 3
    • 4
Then i used the following js: $('#list1 li').click(function(){ $('.list-item').removeClass('list-item'); $(this).addClass('list-item'); }); When I do this the class would only be applied to the outer `
  • `, but I wanted it to be applied to both the parent and child `LI`s. Now my question is, how can I handle this "returns" so I apply the classes to both the parent and child `LI`s? How does js handle these type of selectors? Is the event really running twice and removing the last class that was set?
    @amnotiam i was merely pointing out my thought process, i removed the point of confusion
  • 以上就是How javascript "this" handles multiple selector returns from jquery?的详细内容,更多请关注web前端其它相关文章!

    赞(0) 打赏
    未经允许不得转载:web前端首页 » JavaScript 答疑

    评论 抢沙发

    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址

    前端开发相关广告投放 更专业 更精准

    联系我们

    觉得文章有用就打赏一下文章作者

    支付宝扫一扫打赏

    微信扫一扫打赏