VOOZH about

URL: https://www.geeksforgeeks.org/angular-js/how-to-select-an-element-by-its-class-name-in-angularjs/

⇱ How to select an element by its class name in AngularJS? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to select an element by its class name in AngularJS?

Last Updated : 23 Jul, 2025

Given an HTML document and the task is to select an element by its className using AngularJS. The elements can be selected with the help of a class name using the document.querySelector() method that is used to return the first element that matches a specified CSS selector(s) in the document.

Approach: The approach is to use the element of className class1 that will be selected and its background color is changed to green, by using the document.querySelector() method.

Example 1: This example illustrates for selecting the element by its class name in AngularJS.

Output:

👁 Image
 

Example 2: In this example, the 2 elements of same class are selected and some of the CSS is changed.

Output:

👁 Image
 
Comment
Article Tags:

Explore