JS / jQuery - 获取元素的类型 [英] JS/jQuery - get the type of element
本文介绍了JS / jQuery - 获取元素的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果为了论证我将一个类应用于< p>
和一个< a>
然后我想确定它是< a>
还是< p>
点击了,有办法吗?
If for the sake of argument I'm applying a class to a <p>
and an <a>
and I then want to determine whether it was an <a>
or a <p>
that was clicked, is there a way to do it?
预期用途示例:
$(".selector").click(function(){
element = $(this).whatElementWasClicked(); // return "a" or "p"
}
推荐答案
使用以下内容:
$(".selector").click(function(event){
var element = event.target.nodeName }
这篇关于JS / jQuery - 获取元素的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文