我在 anchor 内有一个 p 标签,在循环期间有许多不同数量的实例。我的目标是悬停时使 p 标签展开并显示更多信息。到目前为止,我已经通过鼠标悬停
来了解这一点。
但是这对我不起作用。有谁有任何想法如何实现这一目标?有人我需要使用传递的参数'e'
来改变高度
boxOPToneplustwo
:这也是一个 a 标签。
$('.boxOPToneplustwo').mouseover(function (e) {
console.log("in");
$(e.target).next('p').addClass("popupHighlight");
});
元素创建:
anchorElement = "<a id='anchor" + countWide + "' class=\"boxOPToneplustwo\" alt=\'"+ image_website +"' style=\"cursor:pointer;width:"+ itemWidth + "px"+";height:"+anchorHeight+";position:absolute;left:"+ locationLeft + "px"+";top:0.3%;\" ><p id=\"test\" class=\"popupDynamic\"> " + popupImageTitles[i] + "</p>";
anchorElement += '</a>';
最佳答案
使用 jQuery,您可以使用 this
来引用已处理的元素。
$('.boxOPToneplustwo').mouseover(function (e) {
console.log("in");
$(this).next('p').addClass("popupHighlight");
});
http://api.jquery.com/mouseover/
主机游戏 例如:尝试将以下代码放入控制台(F12)并查看它对 SO 的作用:P
$("p, span").mouseover(function(){ $(this).css("display", "none"); } );
关于javascript - Jquery鼠标悬停添加css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20757865/