The class Attribute: Using The class Attribute in JavaScript

Using The class Attribute in JavaScript

<script>
function myFunction() {
  var x = document.getElementsByClassName("city");
  for (var i = 0; i < x.length; i++) {
    x[i].style.display = "none";
  }
}
</script>

The class name can also be used by JavaScript to perform certain tasks for elements with the specified class name.

JavaScript can access elements with a specified class name by using the getElementsByClassName() method.

Related concepts

Using The class Attribute in JavaScript

The class Attribute: Using The class Attribute in JavaScript — Structure map

Clickable & Draggable!

The class Attribute: Using The class Attribute in JavaScript — Related pages: