A
A
Anton2021-06-16 02:24:38
JavaScript
Anton, 2021-06-16 02:24:38

How to write a search term for an element on a web page?

Greetings, tell me how to write a condition, for example, if this class is found, then display alert and if not found, do nothing.

var elements = document.getElementsByClassName('testclass');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
targyn, 2021-06-16
@targyn

If the element has a class then output
If (element.classlist.contains('class')){
alert();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question