I want to add multiple classes to an html element
I know the following code is possible.
$("ul#List").find("li.template")
.removeClass("template")
.addClass("entry")
But i want to know if the following code is also possible.?
$("ul#List").find("li.template")
.removeClass("template")
.addClass("entry1")
.addClass("entry2")
$("ul#List").find("li.template")
.removeClass("template")
.addClass("entry1 entry2")
Edit: Take a look http://jsfiddle.net/nHs9W/
Both of the below snippets work
.addClass("entry1 entry2");
.addClass("entry1").addClass("entry2");
you can add multiple classes separated by a space:
.addClass("entry1 entry2")
-1 for not reading the manual !
But anyway, from that page,
.addClass( className )
className: One or more class names to be added to the class attribute of each matched element.
The most important part being one or more
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.