Instructions in the documentation:
angular.element(element)
My own call:
angular.element("xx").addClass("xx")
It’s impossible to implement it at all. Can anyone explain it?
http://jsfiddle.net/twn39/sy38y/1/
習慣沉默2017-05-15 16:52:05
Although angular.element is very close to jQuery, it is still not possible to obtain elements directly through HTML tags. The simplest way is as follows:
angular.element(document.querySelector('p'));
http://jsfiddle.net/sy38y/2/
我想大声告诉你2017-05-15 16:52:05
You can see it by looking at the document
The parameter requirement of angular.element() is HTML string or DOMElement, but what you write is a selector, which does not meet the parameter requirement of angular.element. If you want to use this usage, you need to add jquery
淡淡烟草味2017-05-15 16:52:05
Change it to this:
var par = document.getElementsByTagName('p')[0];
angular.element(par).addClass('blue');
迷茫2017-05-15 16:52:05
Angular does not recommend direct manipulation of the DOM, so if you want to add class, it is recommended to do so (I can't open your connection, I don't know how you wrote the code, so I will use my own)
HTML
<button ng-click="showActive()"></button>
<p ng-class="{'active':show===1}"></p>
js
$scope.showActive=function(){
$scope.show=1;
}
仅有的幸福2017-05-15 16:52:05
Yes, I originally thought about passing the currently clicked button object through ng-click, but in the end I found that Angular does not allow this. . .
I had no choice but to use angular’s built-in jQlite to handle it!