I have a piece of code that is reading how many items are in a shopping basket, I would like to add a class to a div with the id of #basket_count. I know how to add a class to the span tag were the counter is appearing. Not sure how to go from here, any help would be appreciated.
$('span#ctl00_lblItems').filter(function (index) {
return parseInt(this.innerHTML) > 0;
}).addClass("green");
Step 1) Add HTML:Add a class name to the div element with id="myDIV" (in this example we use a button to add the class).
jQuery addClass() Method The addClass() method adds one or more class names to the selected elements. This method does not remove existing class attributes, it only adds one or more class names to the class attribute. Tip: To add more than one class, separate the class names with spaces.
var somevar = "apple" $( .... select all elements with class == somevar ). show();
same way as you added class to your span
$("#basket_count").addClass("your_class");
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