我希望将当前选择器与JavaScript if条件中存储的节点进行比较。
在我的代码中,我创建了一个由image节点和li节点组成的数组。我希望能够将用户当前悬停在其上的li与链接数组中的元素进行比较,例如,当前悬停的链接是否与链接相同
我已经尝试了许多方法来检查jQuery(这)和链接之间的等价性,但我无法通过if语句来确定它们是否相等。你能告诉我如何将当前选择器与存储在数组中的选择器位置进行比较吗?
下面是我的代码(我使用jQuery作为选择器,因为这是一个Wordpress网站):
jQuery("li.menu-cloud").hover( function(){
// Identify the containers of the links and the featured images:
var nav = document.getElementById("nav");
var holder = document.getElementById("img-holder");
// Creates an array of the individual links and featured images of the menu links:
var pics = holder.getElementsByTagName("img");
var links = nav.getElementsByTagName("li");
//Store current li in a variable to test:
var element = jQuery(this);
if ( links[0] == element )
{
alert("links[0] equals this element");
}
else {}
},
function() {
alert("You have left a menucloud link.");
});
https://stackoverflow.com/questions/51340839
复制相似问题