使用 .load() 加载一个针对 的外部元素标签的父级
我正在尝试使用 jQuery .load 事件加载一些外部内容,这一切都很好。我的问题是我正在尝试选择/定位包含特定文本字符串的“a”标签的父元素...
我当前的代码如下:
$('.actionlink').live('click',function() {
$('<div id="info" />').load('/pageURLhere .container a:contains("string of text"):parent',
function() {
.......
目前该代码在引入“a”方面工作正常包含匹配字符串的标签 - 但“:parent”似乎被完全忽略 - 它甚至不会破坏脚本。
这只是为了复杂化选择器组合还是我的设置错误?
外部页面结构是这样的:
<div>
<a href"#">string of text</a>
</div>
我想在 div 中选择并加载,但我只能通过匹配的字符串来定位“a”标签。
I'm trying to load in some external content using the jQuery .load event, which is all fine. my problem is that I'm trying to select/target a parent element of an 'a' tag which contains a certain string of text...
My current code is as follows:
$('.actionlink').live('click',function() {
$('<div id="info" />').load('/pageURLhere .container a:contains("string of text"):parent',
function() {
.......
Currently the code works fine in bringing in the 'a' tag that contains the matched string - but the ":parent" seems to be completely ignored - it doesn't even break the script.
Is this just to complex a selector combination or is my set-up wrong?
The external page structure is something like this:
<div>
<a href"#">string of text</a>
</div>
and I want to select and load in the div but I can only target the 'a' tag by means of a matched string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我希望你的页面很小,因为该选择器的性能会很棒。我会做两件事:
编辑(更多信息):
您的问题可能是由于 jQuery 如何构造页面片段造成的: http://api.jquery.com/load/< /a>
我敢打赌,当它到达 :parent 时,它已经选择了内容,并且没有更多的父级可以获取。
I hope your page is tiny because the performance of that selector is going to be aweful. I'd do two things:
EDIT (more info):
Your issue is likely due to how jQuery constructs the page fragments: http://api.jquery.com/load/
My bet is that by the time it gets to :parent it's already made a selection of content and there's no more parent to get.