JavaScript jQuery addClass not overwriting jquery override addclass

This has been answered quite a few times before and all the responses seem to point to specificity of the CSS, but as far as I can tell, that does not seem to be the case here.

HTML

<button class="flex-item color-2">A</button>
<button class="flex-item color-2">B</button>
<button class="flex-item color-2">C</button>

JS

$("button.color-2").hover( function(){
    $(this).addClass("color-1 bg-2");
}, function(){
    //$(this).removeClass("color-1").removeClass("bg-2");
});

Developer Tools Output

enter image description here

I did change the background to be a class as I realized I had the background specified elsewhere.

Now, when the javascript adds the classes, the background overwrites, but the color does not.

Does addClass not take precedence over pre-defined colors?

Thanks.

Answer:1

Your question

"Does addClass not take precedence over pre-defined colors?"

Jquery addClass has nothing to do with precedence at all as far as I know. The precedence of your css is defined in your css.

For example, the color 2 takes precedence because it is on line 216 and your #fff is on line 215

If you want the added class to take precedence then you need to define it better in your css. Either define it later in the css file or define it with a more specific selector, you could also use !important but you might get into a situation later where !important is not good enough so I would avoid it for now

Answer:2

that wont overwrite because 'color-1 bg-2' classes defined before 'flex-item color-2'.. order your classes in your css.

or

you can use !important on 'color-1 bg-2' classes

.bg-2{display: block !important}

Answer:3

I have an XML file with many nodes that look just like this: <map-item> <location-name>U Lot (Pine Sreet)</location-name> <link>https://maps.google....

I have an XML file with many nodes that look just like this: <map-item> <location-name>U Lot (Pine Sreet)</location-name> <link>https://maps.google....

  1. child element elements
  2. get elements child element jquery
  3. get child elements of element javascript
  4. get child elements of element
  5. element child elements javascript
  6. element child elements java
  7. child elements parent element

I'm trying to get this panel menu to work. I've been working on it for hours without any success. I have it partially working. See fiddle here. What I'm trying to do is: When you click target 1, ...

I'm trying to get this panel menu to work. I've been working on it for hours without any success. I have it partially working. See fiddle here. What I'm trying to do is: When you click target 1, ...

  1. jquery simple slider codepen
  2. jquery simple slider example
  3. jquery simple slide
  4. jquery simple slideshow
  5. jquery simple slider
  6. jquery simple slider code
  7. jquery simple slider plugin
  8. jquery simple slider responsive
  9. jquery simple slider tutorial
  10. jquery simple slider next previous
  11. jquery simple slider with text
  12. jquery simple slider jsfiddle
  13. simple jquery slide menu
  14. simple jquery slider free download
  15. simple jquery slider example with source code
  16. simple jquery slider w3schools
  17. simple jquery slider with next previous buttons
  18. simple jquery slider with dot navigation
  19. simple jquery slider autoplay
  20. simple jquery slider with thumbnails

I have a MessageBox to show in my app, and it is specified that the 'YES' button has to be on the right. How could I change the YESNOCANCEL order ? (in a CANCELNOYES one maybe?) Here's my actual code ...

I have a MessageBox to show in my app, and it is specified that the 'YES' button has to be on the right. How could I change the YESNOCANCEL order ? (in a CANCELNOYES one maybe?) Here's my actual code ...

  1. change button order android
  2. change button order note 9
  3. change order button text woocommerce
  4. change order button
  5. xiaomi change button order
  6. jira change button order
  7. sweetalert2 change button order
  8. bootbox change button order
  9. miui change button order
  10. change new button order and default content type
  11. sweetalert change button order
  12. change slicer button order
  13. css change button order
  14. qmessagebox change button order
  15. change new button order
  16. change new button order sharepoint
  17. change new button order sharepoint 2013
  18. change place order button text woocommerce
  19. change place order button woocommerce
  20. bootbox confirm change button order

I have a habbit of debugging JS and jQuery script in some developer tool. I realized Chrome Dev Tools showing x.fn.x.init as a value for $() and $(this). However I dont realize what are these value: ...

I have a habbit of debugging JS and jQuery script in some developer tool. I realized Chrome Dev Tools showing x.fn.x.init as a value for $() and $(this). However I dont realize what are these value: ...

  1. what does init value mean
  2. what is the unit value of the 3 in 432
  3. what is sem_init value