开发者

how to add multiple css classes to a html element usin javascript

I want to add multiple classes to an html element

I know the following code is possible.

$("ul#List").find("li.template")开发者_如何学Python
            .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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜