Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Wednesday, December 30, 2015

addClass - can add multiple classes on same div?

addClass - can add multiple classes on same div?


jQuery add multiple class

This is my current code, I know its wrong code

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

Answer by maxdec for addClass - can add multiple classes on same div?


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");  

Answer by Al-Mothafar for addClass - can add multiple classes on same div?


You can add multiple classes by separating classes names by a spaces

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

Answer by xdazz for addClass - can add multiple classes on same div?


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');  

Answer by Shibin Ragh for addClass - can add multiple classes on same div?


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

Ref- jQuery

Answer by Ali Zia for addClass - can add multiple classes on same div?


You can simply do the following.

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


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.