[英]Add toggle to jQuery mouseover event to trigger CSS color change
I have below script that works fine when the mouse is hover over the #eventID
then the #targetID
text color turns purple.当鼠标悬停在#eventID
然后#targetID
文本颜色变为紫色时,我有以下脚本可以正常工作。 I hope to add a toggle to the script so that when mouseout
the text color changes back to its original or defined color.我希望在脚本中添加一个切换,以便当mouseout
时文本颜色变回其原始颜色或定义的颜色。
$("#eventID").on ("mouseover",function(){
$("#targetID").css("color","purple");
})
I tried to add the toggle before the css function and before the jQuery event listener, but neither of them works.我尝试在 css 函数和 jQuery 事件侦听器之前添加切换,但它们都不起作用。
Test1:测试1:
$("#eventID").on ("mouseover mouseout",function(){
$("#targetID").toggle(css("color","purple"));})
Test2:测试2:
$("#eventID").toggle(on("mouseover mouseout", function() {
$("#targetID").css("color", "purple");}));
You can use:您可以使用:
$("#eventID").on("mouseover", function() {
$("#targetID").css("color","purple");
}).on("mouseout", function() {
$("#targetID").css("color","");
});
This will clear the inline color style.这将清除内联颜色样式。 when you mouseout.当你鼠标悬停时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.