重复的ID的拧紧jquery选择器? [英] Does duplicate id's screw up jquery selectors?

查看:196
本文介绍了重复的ID的拧紧jquery选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有两个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆