如何使用AngularJS(jqLit​​e)为firstchild添加CSS属性

时间:2016-12-16 08:11:20

标签: jquery angularjs jqlite

我想将css添加到具有特定<div>的{​​{1}}内的第一个<div>元素(firstChild)。如何使用AngularJS(jqLit​​e)实现此目的。

我的 HTML 如下所示:

id

My AngularJS(即使没有选择第一个孩子也不行):

<div id="modulare">
   <div class="ibox-content ibox-content">
     ...
   </div>
   <div class="ibox-content ibox-content">
     ...
   </div>
</div>

希望你能提供帮助。

2 个答案:

答案 0 :(得分:1)

尝试这种方式:

if (angular.element('#modulare.ibox-content').first()){ // I need the first child here
    angular.element('#modulare.ibox-content').first().css("border", "none");
}

答案 1 :(得分:0)

有某些方法可以做到这一点但你可以尝试:

    if (angular.element(document.getElementsByClassName('ibox-content'))){ // I need the first child here

angular.element(document.getElementsByClassName('ibox-content')).css("background-color", "red");
    }

通过css: 拿一个没有边框的课

.noborder{
border:none !important;
 }

你的html中必须有ng-class:

 <div class="ibox-content ibox-content" ng-class="newclass">

在您的控制器中,您可以在不想要边框时添加此类:

$scope.newclass='noborder';

重要提示:未对代码进行测试。根据您的需求创建