Reputation: 2185
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.
Upvotes: 11
Views: 68496
Reputation: 27092
Use attribute selector [attr]
#parentDiv button[disabled] {color: #aaa}
Upvotes: 0
Reputation: 115362
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>
Upvotes: 20
Reputation: 2480
Replace your styles with this
#parentDiv button:disabled
{
color:#F00;
}
Upvotes: 0
Reputation: 9739
You can use CSS3 selector :disabled
#parentDiv button:disabled
{
color:#AAAAAA;
}
Upvotes: 3