E
E
Ekaterina2020-04-13 21:23:07
JavaScript
Ekaterina, 2020-04-13 21:23:07

Why is onclick not working?

Changing the text color p to red on button click does not work.

in html:

<p class="intro">textext....text</p>
<a href="#" class="btn" id="btn">Двигаться к мечте!</a>


before the footer is the path to js: in css

<script src="js/main.js"></script>


.red {
    color: red;
}

in js:
var btn = document.getElementById('btn');

btn.onclick = function () {
  var text = document.querySelector('p.intro');
  text.classlist.add('red');
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
coderisimo, 2020-04-13
@Katherinaabr

classList instead of classlist

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question