不重复ID的搞砸了jQuery选择? [英] Does duplicate id's screw up jquery selectors?
问题描述
如果我有两个div,无论是使用id =myDiv
If I had two divs, both with id="myDiv"
应该 $(#myDiv)淡出();
淡出双方的div了呢?还是会淡出只有第一/第二?或者根本没有?
Would $("#myDiv").fadeOut();
fade both divs out? Or would it fade only the first/second? Or none at all?
我要如何改变它淡出哪一个?
How do I change which one it fades out?
注意:我知道重复的ID是对标准,但我使用的fancybox模式弹出并复制了弹出窗口的内容网页上指定的内容。如果有人知道解决这个(也许我使用错误的fancybox)的方式,请让我知道。
Note: I know duplicate id's is against standards but I'm using the fancybox modal popup and it duplicates specified content on your page for the content of the popup. If anyone knows a way around this (maybe I'm using fancybox wrong) please let me know.
推荐答案
jQuery的只有一个元素在查询的ID匹配时。至多一个元素
对象的数组将 $(#富)返回。获得()
。请参阅 jQuery的文档了解更多信息,或者自己尝试一下。
jQuery matches exactly one element when querying for an ID. An array of at most one Element
object will be returned by $("#foo").get()
. See the jQuery documentation for more information, or try it yourself.
$(function() {
alert($("#foo").length);
});
这篇关于不重复ID的搞砸了jQuery选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!