M
M
maxon_by2018-02-02 17:28:32
JavaScript
maxon_by, 2018-02-02 17:28:32

What is the difference between .className('') ​​and .classList.add('')?

Hello dear experts! In the process of learning JS, a question appeared:
.getElementById('id').className = 'class'
.getElementById('id').classList.add('class');
what are their differences (I mean .className and .classList) ?
Thanks for answers!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Spirin, 2018-02-02
@maxon_by

tyts , tyts

O
Oleg, 2020-12-25
@Oleg714

className - string
classList - object, it's faster and easier to work with. But there is no replace in it, it is replaced by toggle

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question