Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery add class to specific div

Tags:

jquery

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");
like image 664
Noel Sheppard Avatar asked Jul 28 '15 16:07

Noel Sheppard


People also ask

How do I add a class to a div?

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).

How can I add class in jQuery?

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.

How do you select all elements with the class of Apple in jQuery?

var somevar = "apple" $( .... select all elements with class == somevar ). show();


Video Answer


1 Answers

same way as you added class to your span

$("#basket_count").addClass("your_class");
like image 195
Pepo_rasta Avatar answered Oct 02 '22 15:10

Pepo_rasta