S
S
Stacy None2018-03-03 10:40:41
JavaScript
Stacy None, 2018-03-03 10:40:41

How to add css class to an element?

There is a div with already existing css class "list"

<div class="list">
..text..
</div>

You need to add the "vote" class to this div. To make it look like this:
<div class="list vote">
..text..
</div>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Adam Sulumov, 2018-03-03
@Stacy11

native js:

let list = document.querySelector('.list');
list.classList += ' vote';

$(".list").addClass("vote");

A
Alexander, 2018-03-03
@pi4yyy

const a = document.querySelector('.list');
a.classList += ' vote';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question