我想将CSS添加到数组的每个元素
我当前的代码是
var elaboration = $('.conception-competences-elaboration').children('img');
var realisation = $('.conception-competences-realisation').children('img');
var conception = $('.conception-competences-conception').children('img');
function up() {
elaboration.on('mouseover', function() {
elaboration.css('padding-bottom', '5px');
elaboration.css('cursor', 'pointer');
})
realisation.on('mouseover', function() {
realisation.css('padding-bottom', '5px');
realisation.css('cursor', 'pointer');
})
conception.on('mouseover', function() {
conception.css('padding-bottom', '5px');
conception.css('cursor', 'pointer');
})
}
这行得通,但是我想减少代码行,所以我创建了一个数组,并尝试了此操作:
var actionsArray = ['elaboration', 'realisation', 'conception'];
function up() {
for (var i = 0; i < actionsArray.length; i++) {
actionsArray[i].on('mouseover', () => {
actionsArray[i].css('padding-bottom', '5px');
actionsArray[i].css('cursor', 'pointer');
})
}
}
但这不起作用,有人可以帮助我吗?
谢谢!