问题描述
我有一些必须处理的可怕代码
I have bits of horrible code I have to deal with
...
<div class="container">
...
<tr>
<td width="100" height="50">
<a class="swaps"><img src="http://www.blah.jpg" alt="Some Title" id="1"></a></span></td>
</tr>
<tr>
<td width="100" height="50">
<a class="swaps"><img src="http://www.blah2.jpg" alt="Another title" id="2"></a></span></td>
</tr>
</div>
如果我使用
var thisone = $("#container .swaps:first")
选择第一个(ID为1)为什么我在选择
to select the first one (with id 1) why do I have trouble selecting
thisone.next()
?
推荐答案
HTML是真正的HTML吗?我没有看到ID为容器"的任何元素,而您正在
The HTML is the real one? I don't see any element with id "container" and you're doing
$("#container .swaps:first")
此外,如果它是真正的HTML,则应对其进行一些修复(关闭img标签,并在</TD>之前添加跨度的开始标签)
Also, if it's the real HTML, you should fix it a little (close the img tag, and add the opening tag for the span before the </TD>)
假设您的HTML没问题,这应该适用于您的方案.
Supposing that your HTML is OK this should work for your scenario.
var thisone = $("#container .swaps:first");
thisone.children();
IMG不是主播,是孩子.
The IMG is not sibling of the anchor, is a child.
这篇关于jQuery在元素上不相邻的next()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!