我有一些可怕的代码需要处理
...
<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),为什么我在选择时遇到问题
thisone.next()
发布于 2010-04-07 11:17:29
HTML是真的吗?我没有看到任何id为"container“的元素,而你正在做
$("#container .swaps:first")
而且,如果它是真正的HTML,您应该对其进行一些修改(关闭img标记,并在
假设您的HTML是OK的,那么这应该适用于您的场景。
var thisone = $("#container .swaps:first");
thisone.children();IMG不是锚的同级,而是子对象。
发布于 2010-04-07 11:17:45
因为,正如Jquery文档所说:
:第一个伪类等同于:eq(0)。它也可以写成:lt(1)。虽然这只匹配一个元素,但:first-child可以匹配多个元素:每个父元素对应一个元素。
尝试像在$(selector).children();中一样使用.children()
发布于 2010-04-07 11:19:03
下一个()方法检查同级容器您的场景中没有其他同级容器具有.swaps class...try $(“# matches...in .swaps")
https://stackoverflow.com/questions/2589755
复制相似问题