Grow your CSS skills. Land your dream job.

Change all elements BUT the one clicked Jquery.

  • # May 16, 2013 at 9:55 pm

    I have 10 divs. I want all to change color onclick BUT the one clicked. I know i can select all elements like this

    $(“*”).css(“background-color”,”red”);

    They all change colors but i want the one that is clicked to remain the same.

    # May 16, 2013 at 10:07 pm

    Something like this: http://codepen.io/anon/pen/shlrb

    And do not ever use `*` to select items (this select EVERYTHING). With JavaScript you want to be really specific.

    Free jQuery course: https://tutsplus.com/course/30-days-to-learn-jquery/

    # May 16, 2013 at 10:17 pm

    `$(‘.it’).not($(this))` will give all matched items except the one clicked. However, in this instance I would do exactly what @AlenAbdula has posted.

    # May 16, 2013 at 10:29 pm

    Works perfectly, Thank you.

    # May 17, 2013 at 5:21 am

    `$(‘.it’).not($(this))` is the same as `$(‘.it’).not(this)` (the function accepts a DOM Element as well)

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".