2

I want to select all elements in my page except those with the class "searchBox".

How can I do that?

I want to disable text selection on all elements except input elements

1
  • You mean you want to prevent the user from selecting text? Why? That's a terrible user experience. If you're trying to keep it from being copied, they can just disable JS or view source to get around that. Don't put it on the internet if you don't want it copied. Commented Jan 7, 2010 at 19:02

1 Answer 1

6
$('* :not(.searchBox)'); 

* : Matches all elements.

not: Filters out all elements matching the given selector

Sign up to request clarification or add additional context in comments.

2 Comments

Are you sure about the space between * and :not ? Space is the descendant operator in CSS selectors.
$(':not(.searchBox)'); will work almost the same. @subtenante - usually, you are correct, and adding the space is a common mistake. Here it doesn't matter though, because all element are under something anyway (all elements are under <body> or deeper, so this version may miss the body tag).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.