获取下一个DOM元素的ID
16lz
2021-01-22
How do I get the ID of the element after a class that is clicked?
如何在单击的类之后获取元素的ID?
3 个解决方案
#1
1
Try this:
$(".className").click(function() {
$(this).next().attr("id");
});
$(".className")
: select elements with classclassName
.click()
: jQuery onclick handler$(this)
: selects element again.next()
: get next element.attr("id")
: retrieveid
attribute
$(“。className”):选择类className的元素
.click():jQuery onclick处理程序
$(this):再次选择元素
.next():获取下一个元素
.attr(“id”):检索id属性
If you want to get it on click, add a click()
handler
如果要单击它,请添加click()处理程序
更多相关文章
- iframe操作、调用父页面元素或js函数
- Angularjs在ng-repeat中找到最后一个可见元素
- 浏览器如何处理HTML元素上的无效/未指定的属性?
- 为什么推荐把<script>元素写在body里面
- 在bootstrap中为同一元素使用两个数据切换
- 如何获取knockoutjs可观察数组的下一个元素?
- eventListener将添加到父级,但子元素干扰
- 单击元素后的load()特定href
- 如何在jquery galleria中滑动包含内部元素的div?