重复的ID的拧紧jquery选择器? [英] Does duplicate id's screw up jquery selectors?
问题描述
如果我有两个div,两个id =myDiv
If I had two divs, both with id="myDiv"
会 $(#myDiv)。
fade both divs out?还是只会淡出第一/第二?
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模式弹出窗口,它重复了您的页面上的指定内容的弹出窗口内容。
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时。最多一个元素
对象的数组将由 $(#foo)。get()
返回。有关详情,请参阅 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屋!