选择变量的嵌套元素-jQuery [英] Selecting a variable's nested elements - jQuery

查看:46
本文介绍了选择变量的嵌套元素-jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将变量传递给函数,并让函数在该变量中选择元素.我不熟悉这种情况的语法,有人可以建议吗?

I wish to pass a variable to a function and have the function select elements within that variable. I'm unfamiliar with the syntax of this case however, could any one advise?

例如,当在容器中单击一个按钮时,我希望将该容器存储在变量中,好吧,我有那部分.但是然后我希望在该容器中选择某个元素,例如

For example, when a button is clicked within a container I wish for that container to be stored in a variable, okay I have that part. But then I wish to select a certain element within that container like

$(container "div#element");

如何将两者结合在一起,并指出这些元素可能嵌套得很深?

How can you combine the two, noting that these elements could be deeply nested?

推荐答案

jQuery获得第二个参数,该参数确定选择的范围.例如,$('#first-name', '#registration-form')仅匹配registration-form中ID为first-name的元素.

jQuery gets a second parameter, which determines the scope of the selection. For example $('#first-name', '#registration-form') only matches elements with the first-name id inside registration-form.

我想您可以使用此功能.我认为$("div#element", container);可以工作.

I guess you can use this feature. I think $("div#element", container); would work.

请参见此小提琴.

这篇关于选择变量的嵌套元素-jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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