-1
我的页面上有一些元素。这些是他们中的一些:用Jquery选择类元素
<div class="tile 11"></div>
<div class="tile 35"></div>
<div class="tile 89"></div>
我想要一个CLASS元素进入变量,只要我把它悬停在变量中。
我试图
$(".tile").mouseenter(function(){ //on mouse over
$(this).css("background-color", "red"); //check if selected
myVariable = $(this).css; //then place css into variable
}).mouseleave(function() { //..and when I leave it
$(this).removeAttr("style"); //remove color
});
但它没有工作。
例如,当我悬停第一个图块时,“myVariable”应该是“图块11”,但它不是。为什么?
尝试'$(本).attr的''而不是$(本)( “类”).css' –
@SandeepNayak真正奏效。非常感谢:) – Kajcioch