Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
74 views
in Technique[技术] by (71.8m points)

javascript - Can I add a class with spaces to an element?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It looks like if you want to add more than one class that you need to comma separate them.

arrowIcon.classList.add("fa", "fa-arrow-right");

You can also do this programatically:

var classNames = "fa fa-arrow-right":

arrowIcon.classList.add.apply(arrowIcon.classList, classNames.split(" "));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...