JavaScript How to specify adding classes

I need to add a .trash class to every element inside a .secondary-images div, except for one .field--name-rd-page-secondary-image div.

I have tried this.

$('.secondary-images *').addClass('trash').not(".field--name-rd-page-secondary-image");

But it doesn't work.

Does anyone know.

Answer:1

Place the ".not" before the addClass:

$('.secondary-images *').not(".field--name-rd-page-secondary-image").addClass('trash');
Answer:2

Use either:

$('.secondary-images *').not(".field--name-rd-page-secondary-image").addClass('trash');

$('.secondary-images *').not(".field--name-rd-page-secondary-image").addClass('trash');
.trash {
  color: red
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="secondary-images">
  <p>p</p>
  <p>p</p>
  <p class="field--name-rd-page-secondary-image">p</p>
  <p>p</p>
  <p>p</p>
</div>
Answer:3

This worked for me too.

$('.secondary-images *').not(".field--name-rd-page-secondary-image, .field--name-rd-page-secondary-image .field__item, .field--name-rd-page-secondary-image .field__item picture, .field--name-rd-page-secondary-image .field__item picture source, .field--name-rd-page-secondary-image .field__item picture img").addClass('trash');

I have added extra items because i wanted to avoid all those too.

Answer:4

I have this ul li html element: <ul id="langMenu" class="top-links list-inline"> <li> <a class="dropdown-toggle no-text-underline" ...

I have this ul li html element: <ul id="langMenu" class="top-links list-inline"> <li> <a class="dropdown-toggle no-text-underline" ...

  1. fetch value from dictionary in python
  2. fetch value from map in java
  3. fetch value from dictionary in c#
  4. fetch value from json object in javascript
  5. fetch value from json object
  6. fetch value from json
  7. fetch value from database in php
  8. fetch value from json array
  9. fetch value from datatable in c#
  10. fetch value from json object in java
  11. fetch value from set in java
  12. fetch value from list in java
  13. fetch value from array in php
  14. fetch value from object in javascript
  15. fetch value from json string in java
  16. fetch value from tuple python
  17. fetch value from map
  18. fetch value from json array in java
  19. fetch value from promise
  20. fetch value from dataset in c#

I have 2 buttons yes and no, and simply I am toggling them. <!DOCTYPE html> <html> <head> <title>Demo Project</title> </head> <...

I have 2 buttons yes and no, and simply I am toggling them. <!DOCTYPE html> <html> <head> <title>Demo Project</title> </head> <...

  1. radio button checked by default
  2. radio button checked html
  3. radio button checked jquery
  4. radio button checked not working
  5. radio button checked attribute
  6. radio button checked css
  7. radio button checked event
  8. radio button checked value
  9. radio button checked c#
  10. radio button checked angular
  11. radio button checked react
  12. radio button checked value jquery
  13. radio button checked false
  14. radio button checked event angular 6
  15. radio button checked in javascript
  16. radio button checked or not in jquery
  17. radio button checked event jquery
  18. radio button checked android
  19. radio button checked by default html
  20. radio button checked php

I have a trie (also called a prefix tree). Given a prefix, I want to get a list of ten words that start with the prefix. The thing that's unique about this problem is that I only want 10 of the ...

I have a trie (also called a prefix tree). Given a prefix, I want to get a list of ten words that start with the prefix. The thing that's unique about this problem is that I only want 10 of the ...

I'm trying to get data from a server in my AngularJS app, using $http.get. But when I execute the request, it seems to get cancelled by something. It happens with every link I use. Local files are ...

I'm trying to get data from a server in my AngularJS app, using $http.get. But when I execute the request, it seems to get cancelled by something. It happens with every link I use. Local files are ...

  1. angularjs http request
  2. angularjs http request example
  3. angularjs http request timeout
  4. angularjs http request default timeout
  5. angularjs http request headers
  6. angularjs http request in loop
  7. angularjs http request interceptor example
  8. angularjs http request interceptor
  9. angularjs http request progress bar
  10. angularjs http request error handling
  11. angularjs http request synchronous
  12. angularjs http request parameters
  13. angularjs http request cors
  14. angularjs http request body
  15. angularjs http request json
  16. angularjs http request multipart/form-data
  17. angularjs http request cross domain
  18. angularjs http request method options
  19. angularjs http request content type
  20. angularjs http request form data