Reputation: 473
I currently have a JavaScript function that uses getElementsByClassName("apples")
to find everything in the class apples
. My problem is that I can't seem to find a way to fetch every element not in the class apples
. Is there any helper functions in JavaScript that might allow me to do this? Thanks for the help!
Upvotes: 1
Views: 2977
Reputation: 339816
You can't do it with getElementsByClassName
.
The easiest way on modern browsers would be to use:
document.querySelectorAll(':not(.apples)')
On older browsers you'd probably have to use document.getElementsByTagName('*')
followed by a filtering operation to remove the unwanted elements. This would probably be very slow.
Upvotes: 8