AngularJS Set Get and Remove Attribute Dynamically Form Element

AngularJS Set Get and Remove Attribute Dynamically Form Element

In this Post We Will Explain About is AngularJS Set Get and Remove Attribute Dynamically Form Element With Example and Demo.Welcome on infinityknow.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Set Attribute or Remove Attribute using AngularJSExample

In this post we will show you Best way to implement AngularJS remove HTML attributes Example, hear for angularjs – conditionally add an element attributewith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

READ :  Simple Way Laravel Installation step by step using composer

Angularjs read attribute value of an HTML elemnt

var myparm = angular.element( document.querySelector( '#live_divid' ) );
alert(myparm.attr('tempattrval'));

Angularjs set attribute value of an HTML element

var myparm = angular.element( document.querySelector( '#live_divid' ) );
myparm.attr('tempattrval',"attr val");

Angularjs remove attribute of an HTML element

var myparm = angular.element( document.querySelector( '#live_divid' ) );
myparm.dltAttribute('tempattrval');

Angularjs Set Attribute or Remove Attribute using AngularJS

<!DOCTYPE html>
<!DOCTYPE html>
<html ng-app="" ng-controller="liveCtrl">
<body>
<button ng-click="readAttrval()">
  Read HTML Attribute value
</button>
<hr/>
<button ng-click="setAttr()">
  Set HTML Attribute value
</button>
<hr/>
<button ng-click="dltAttribute()">
  Remove HTML Attribute value
</button>
<hr/>
<div tempattrval="val" id="live_divid">
  HTML Attribute DIV
</div>
<script>
function liveCtrl($scope) {
    $scope.readAttrval = function() {
     var myparm = angular.element( document.querySelector( '#live_divid' ) );
     alert(myparm.attr('tempattrval'));
    }
    $scope.setAttr = function() {
     var myparm = angular.element( document.querySelector( '#live_divid' ) );
     myparm.attr('tempattrval',"attr val");
     alert("HTML attribute set");
    }
    $scope.dltAttribute = function() {
     var myparm = angular.element( document.querySelector( '#live_divid' ) );
     myparm.dltAttribute('tempattrval');
     alert("HTML attribute removed");
    }
}
</script>
<script src="angular.min.js"></script>
</body>
</html>

Example

READ :  AngularJS Contact Form Send Email with Attachment using PHP

I hope you have Got What is angularjs – conditionally add an element attribute And how it works.I would Like to have FeadBack From My Blog(infinityknow.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(infinityknow.com) Are Most Always Welcome.

Add a Comment

Your email address will not be published. Required fields are marked *