addClass - can add multiple classes on same div?

Jquery

Jquery Problem Overview


jQuery add multiple class

This is my current code, I know its wrong code

$('.page-address-edit').addClass('test1').addClass('test2');

Jquery Solutions


Solution 1 - Jquery

$('.page-address-edit').addClass('test1 test2 test3');

Ref- jQuery

Solution 2 - Jquery

You can do

$('.page-address-edit').addClass('test1 test2');

More here:

> More than one class may be added at a time, separated by a space, to the set of matched elements, like so: > > $("p").addClass("myClass yourClass");

Solution 3 - Jquery

You can add multiple classes by separating classes names by spaces

$('.page-address-edit').addClass('test1 test2 test3');

Solution 4 - Jquery

You code is ok only except that you can't add same class test1.

$('.page-address-edit').addClass('test1').addClass('test2'); //this will add test1 and test2

And you could also do

$('.page-address-edit').addClass('test1 test2');

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHunterView Question on Stackoverflow
Solution 1 - JqueryShibinRaghView Answer on Stackoverflow
Solution 2 - JquerymaxdecView Answer on Stackoverflow
Solution 3 - JqueryAl-MothafarView Answer on Stackoverflow
Solution 4 - JqueryxdazzView Answer on Stackoverflow