Sim*_*imo 0 javascript css jquery image jquery-selectors
我有一个查询,当鼠标在图像上时,对列表项的文本进行更改,我在查询中放置了一个事件目标:
$('img').on('mouseover', function(){
// I would like an Id of a text instead of the 'li'
$('li').css('text-decoration', 'underline');
});
$('img').on('mouseout', function(){
$('li').css('text-decoration', 'none');
});
Run Code Online (Sandbox Code Playgroud)
但我希望将其更改为仅应用于与图像具有相同ID的项目:
s[i++] = '<li id=\"'+ vizList[j].name +'\">';
s[i++] = '<a>'+ vizList[j].name + '</a>';
s[i++] = '<img id=\"'+ vizList[j].name +'\" src="../renderer/bundles/' + vizList[j].icon + '" width="268" height="120" style="display:block"/>';
s[i++] = '</li>';
Run Code Online (Sandbox Code Playgroud)
以下代码是您所期望的吗?
$('img').on('mouseover', function(event){
$(event.target).closest('li').css('text-decoration', 'underline');
});
$('img').on('mouseout', function(event){
$(event.target).closest('li').css('text-decoration', 'none');
});
Run Code Online (Sandbox Code Playgroud)