user4531599
user4531599

Reputation:

Select parent element in angular

I want to select parent (searchres) in angular and get style to it but I can't do it ! My HTML is this :

    <div ng-repeat="product in products" class="searchres">
         <a href="#">
              <img src="{{product.path}}" class="img-thumbnail" alt="{{product.name)}}" />
              {{product.name}}                            
         </a>
    </div> 

And my code is this :

$.each($scope.products, function(index, value) {
      var namePro = value.name; 
      if (namePro.length <= 32) {
          $("body").find(".searchres").css("line-height","50px!important");// is wrong !       
          value.parentNode.css("line-height","50px!important"); // is wrong !       
      }
});

what should I do for this problem ?

Upvotes: 1

Views: 566

Answers (1)

spottexj
spottexj

Reputation: 161

There is no need for Javascript code at all in this example. You can use the ng-class directive to attach a class to your div under certain conditions.

<div ng-repeat="product in products" class="searchres" ng-class="product.name.length <= 32 ? 'your-class-name' : ''">
     <a href="#">
          <img src="{{product.path}}" class="img-thumbnail" alt="{{product.name)}}" />
          {{product.name}}                            
     </a>
</div>

Upvotes: 2

Related Questions