0

In an event handler, where $(this) is an element that matches a .myclass

how do I select all other .myclass elements, except $(this)?

Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244
  • 2
    `$('.myclass').not(this)` – Regent Apr 22 '15 at 06:57
  • 2
    It's well worth your time reading through [the jQuery API](http://api.jquery.com) from beginning to end. It only takes about an hour, and it pays you back that time almost immediately. – T.J. Crowder Apr 22 '15 at 06:57
  • Also, please do seach before posting a question. The question linked above was the third hit for the search "select elements except this" on A Famous Web Search Engine. (The others were variations on the theme, generally leading to `.not`.) – T.J. Crowder Apr 22 '15 at 07:00
  • This is not a duplicate, the other question not only marked as a drupal question with drupal code, but also the question and answer are not concise and direct. Directing others to a long question just because the answer is kind of the same and "generally leading to" the same answer does not contribute to people who need answers and want to learn. – Nick Ginanto Apr 22 '15 at 07:10

1 Answers1

2

You can use not():

$('.myclass').not(this)
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339