Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apply css class to "button" inside div

Tags:

html

css

I have a div containing a button as below,

<div id="parentDiv">
    <button id="myBtn" class="myclass">ADD ME</button>
</div>

a new attribute gets added to this button from JS and it becomes like below ('disabled' attribute is added)

<div id="parentDiv">
    <button id="myBtn" class="myclass" disabled="disabled">ADD ME</button>
</div>

I'm trying to apply below CSS class for disabled button,

#parentDiv button.disabled {
    color: #AAAAAA;
}

But to my surprise this class is not getting applied to button. Please point me the correct direction.

like image 316
ScrapCode Avatar asked Apr 15 '15 10:04

ScrapCode


2 Answers

You need to add the attribute selector

#parentDiv button[disabled="disabled"] 
{
    color:red;
}

or just

#parentDiv button[disabled] 
{
    color:red;
}

#parentDiv button[disabled="disabled"] {
  color: red;
}
<div id="parentDiv">
  <button id="myBtn" class="myclass" disabled="disabled">ADD ME</button>
</div>
like image 77
Paulie_D Avatar answered Oct 07 '22 09:10

Paulie_D


You can use CSS3 selector :disabled

#parentDiv button:disabled
{
    color:#AAAAAA;
}

DEMO HERE

like image 42
Luís P. A. Avatar answered Oct 07 '22 10:10

Luís P. A.