Answer the question
In order to leave comments, you need to log in
How to add a class when hovering over a block in Angular?
There are several tr lines:
<tr class="list">
<td class="buy">0/10</td>
<td><a class="buy-button">Купить</a></td>
</tr>
$( document ).ready(function() {
$('#content1 tr.list:nth-of-type(1) .buy-button').addClass('buyButtonSelected');
$('#content1 tr.list').hover(function(){
$('#content1 tr.list').removeClass('buyButtonSelected');
$(this).addClass('buyButtonSelected');
});
});
Answer the question
In order to leave comments, you need to log in
angular.ru/api/ng.directive:ngClass
HTML
<div ng-app>
<table ng-controller="buyCtrl">
<tr ng-repeat="product in products" ng-mouseover="productHovered($index)">
<td >{{product.name}}</td>
<td class="buy">{{product.count}}/10</td>
<td><a ng-class="product.buttonCss">Купить</a></td>
</tr>
</table>
</div>
.red{
color:red;
}
.green{
color:green;
}
function buyCtrl($scope) {
$scope.products = [
{name:'Помидоры', count:1, buttonCss:"green"},
{name:'Огурцы', count:0, buttonCss:"green"},
{name:'Картофель', count:0, buttonCss:"green"}
];
$scope.productHovered = function(selectedProductIndex){
$scope.products.forEach(function(product){
product.buttonCss = "green";
});
$scope.products[selectedProductIndex].buttonCss = "red";
}
}
I think here you can get by with a bunch of ng-mouseover and ng-class. On mouseover, we save the value of the current line in some variable, for example $scope.currentIndex (if the output is done through ng-repeat, then $index will do) . In ng-class we add a class in the case when $index is equal to currentIndex.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question