Enigma
Enigma

Reputation: 859

How to disable CSS Class on particular DIV

I want to disable class automatically applied on div.

<div class="A B">

I want to disable Class 'A' but not 'B'. How could I do that ?

Upvotes: 1

Views: 66150

Answers (5)

Agniswar Chakraborty
Agniswar Chakraborty

Reputation: 287

This code will act magically....

<script type='text/javascript'>
        jQuery(document).ready(function ($) {
        $( "div" ).removeClass( 'your_class_name' );
      });
</script>

Upvotes: 0

Matthew Shaile
Matthew Shaile

Reputation: 105

If you want to do this in straight js, give the div an ID:

<div id="myDiv" class="A B"></div>

And then in js:

document.getElementById("myDiv").classList.remove("B");

Upvotes: 2

user7382438
user7382438

Reputation:

I think that I accomplished succesefully. :)

For example I have my html code :

<a class="m2" href="#">Some text here, with bold</a>
<a class="m2 nobold" href="#">Some text here, without bold</a>

I use CSS for the first text

.m2 {
    font-weight: bold;
}

And for disable it, I use

.nobold {
font-weight: normal;
}

And it apply both, but you can change settings from the other CSS class ...

Upvotes: 0

yunzen
yunzen

Reputation: 33439

I think you are looking for CSS that says. Don't listen to class A.

Alas, there is no such CSS.

  • Either you have to remove the class A from your source code.
  • Or you remove the class from the DOM by means of JavaScript.
  • Or you must overwrite your CSS in class B that any value that was set in class A gets initial/neutral values (sometimes it's the value 'initial', sometimes its the value 'auto' or 'none')

Upvotes: 12

daker
daker

Reputation: 3540

You are probably looking for a javascript...

Add a id to your div and use

<div id="whatever" class="A B"></div>

<script type="text/javascript">
    window.document.onload = function(){ 
        document.getElementById("whatever").className = "A";
    }     
</script>

Upvotes: 4

Related Questions