最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to set CSS styles within Link function of Angular directive - Stack Overflow

programmeradmin1浏览0评论

I'm attempting to set CSS styles on a certain class within a custom Angular directive when it is clicked. I want to acplish this (and any other DOM manipulation) within the Link function. Below is what I have so far, but I'm getting an address.on is not a function error. How would I properly set the CSS -webkit-filter: none on the blur class when blur class elements are clicked?

function link(scope, element, attributes) {
  var address = element[0].getElementsByClassName('blur');
  address.on('click', function() {
    address.css({'-webkit-filter': 'none'});
  });
}

I'm attempting to set CSS styles on a certain class within a custom Angular directive when it is clicked. I want to acplish this (and any other DOM manipulation) within the Link function. Below is what I have so far, but I'm getting an address.on is not a function error. How would I properly set the CSS -webkit-filter: none on the blur class when blur class elements are clicked?

function link(scope, element, attributes) {
  var address = element[0].getElementsByClassName('blur');
  address.on('click', function() {
    address.css({'-webkit-filter': 'none'});
  });
}
Share Improve this question asked Jun 30, 2015 at 15:09 MattDionisMattDionis 3,61610 gold badges55 silver badges110 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

address is a DOM element. You need to wrap it in angular.element to turn it into a jqLite object:

function link(scope, element, attributes) {
  var address = angular.element(element[0].getElementsByClassName('blur'));
  address.on('click', function() {
    address.css({'-webkit-filter': 'none'});
  });
}
发布评论

评论列表(0)

  1. 暂无评论