Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Get HTML element using class name or Id in AngularJS

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 11.8k
    Comment on it

    Hi All,

    In this blog we will see how easy is to get HTML element in AngularJS. We many a times stuck in situation where we need to get HTML element that are not bind to AngularJS Model. Here is quick and easiest way of doing that.

    Using Class Name:

    var elem = angular.element(document.querySelector(".ClassName"));

    Using Id:

    var elem = angular.element(document.querySelector("#Id"));

    Using this can help in getting the HTML element in AngularJS.

    Sample Code:

        <script src=""></script>
        <div ng-app="myApp" ng-controller="myCtrl">
            <input type="text" id="txtSample1" value="Hello" class="clsSample" />
            <input type="text" id="txtSample2" value="Hello" />
            <input type="button" id="btnShow" value="Show" ng-click="showval();" />
            var app = angular.module("myApp", []);
            app.controller("myCtrl", function ($scope) {
                $scope.showval = function () {


    Happy Coding....

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: