jQuery选择器是否从HTML对象而不是从文档根目录中选择? [英] jQuery selectors select from an HTML object other than from document root?
本文介绍了jQuery选择器是否从HTML对象而不是从文档根目录中选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
jQuery选择器从文档中选择.
我如何从根以外的其他地方选择?
假设我要从HTML对象中选择一些子代.
jQuery selectors select from the document.
How do I select from somewhere else other than root?
Say I want to select some children from an HTML object.
为此
function dothis(obj)
{
$j("#tabs").removeClass();
$j("#tabs>ul").removeClass();
$j("#tabs>ul>li>a").each(function()
{
var tabNum = $j(this).attr("href").replace("#", "");
var tabContent = $j("div[id=" + tabNum + "]");
tabContent.removeClass();
$(tabContent).before("<br><h1>" +$j(this).text() + "</h1>\n" );
});
$j("#tabs>ul").each(function()
{
$j(this).empty();//remove Ul links on top
});
}
我想从传递给参数的HTML对象(obj
)中引用选择器,而不是从文档中选择.
I want to reference the selectors from an HTML Object (obj
) i passed into as argument, instead of selecting from document.
这行得通!
$j("#tabs", obj).removeClass();
推荐答案
您可以为选择器提供第二个参数以精确显示上下文:
You can give a second parameter to your selector to precise the context :
$j("#tabs", obj).removeClass();
这篇关于jQuery选择器是否从HTML对象而不是从文档根目录中选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文