I have a div with Class. For example
<div class="button check"></div>
.The css is defined for both 'button','check'. I want to access the above div through jquery and write something in the div.I tried with
$('.button check').html("sample data");
I do not see anything being written when I run the page.
Please help me.
Just chain the CSS classes together, separated by periods:
$('.button.check').html("sample data");
You will also see better performance in some browsers, by specifying the tag name as well:
$('div.button.check').html("sample data");
Update: After reading Brian's answer, I re-read the original question I realized you might be under the impression you need to use both to reference the div
. If you had:
<div class="button cancel">Cancel</div>
<div class="button check">Check</div>
Then chaining selectors (i.e. .button.cancel
) would make sense. However, if it was the only div
on the page or you wanted all the divs
with button
class, you don't need both classes:
<div class="button check">Check</div>
This would select it fine:
$('div.check').html("sample data");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With