作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一定错过了一些非常重要的东西,我一直在使用 .parent().parent().parent().. 等来遍历 DOM 和 .next().next() 来遍历 DOM。
我知道这是错误的,我需要更可靠的东西,我需要一个选择器,它将从单击的元素 $(this) 向下遍历 DOM,以查看单击的元素是否位于具有“last”类的元素内”。
div.last > div > table > tr > td > a[THE ITEM CLICKED is in the element last]
和
div > div > table > tr > td > a[THE ITEM CLICKED is not in the element last]
如果结果有长度
var isWithinLastRow = [amazingSelector].length;
在这种情况下做其他事情。
最佳答案
HTML:-
<div class="last">
<div>
<table>
<tr>
<td>
<a>Test</a>
</td>
</tr>
</table>
</div>
</div>
<div>
<div>
<table>
<tr>
<td>
<a>Test</a>
</td>
</tr>
</table>
</div>
</div>
JS:-
jQuery(function($){
$("a").on("click",function(){
if($(this).closest(".last").length>0)
{
alert("Clicked anchor with div parent class as last");
}
});
});
关于jQuery:如果所选元素 $(this) 的父元素的类名为 'last',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17068838/
我正在尝试用 Swift 编写这段 JavaScript 代码:k_combinations 到目前为止,我在 Swift 中有这个: import Foundation import Cocoa e
我是一名优秀的程序员,十分优秀!