检查元素类型单击 [英] check element type clicked
本文介绍了检查元素类型单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
除了链接之外,我有一个要扩展/收缩的div.我有以下代码,该代码有效,但缺少异常.确保div"expandablediv"中的所有元素和区域引起jquery扩展/收缩的最有效方法是什么,元素除外.
I have a div that I want to expand/contract with the exception of links. I have the following code, which works but lacking the exception. What is the most efficient way of ensuring all elements and areas within the div "expandablediv" cause expand/conract with jquery, with the exception of the element.
$("#expandablediv").click(function () {
if ($("#withinexpandlediv").is(":hidden")) {
$("#withinexpandlediv").fadeIn(50);
}
else {
$("#withinexpandlediv").fadeOut(50);
}
});
HTML代码:
<div id="expandablediv" >
<div class="ddImage">
<img src="rightArrow.png" alt="Title">
</div>
<div class="ddText">
Title
</div>
<div id="withinexpandlediv" >
Text contains one or more <a href="mailto:email@links.com"> email links.</a>
</div>
</div>
推荐答案
If you mean you don't want links to trigger the toggle, use event.target.nodeName:
$("#expandablediv").click(function (e) {
if (e.target.nodeName == "A") { return; }
//if ($(e.target).is('a')) { return; } // also works
if ($("#withinexpandlediv").is(":hidden")) {
$("#withinexpandlediv").fadeIn(50);
}
else {
$("#withinexpandlediv").fadeOut(50);
}
});
nodeName
: http://jsfiddle.net/m7vpk/
is()
: http://jsfiddle.net/FQuzt/
这篇关于检查元素类型单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文