关于头获取股利ID点击,手风琴 [英] Getting Div ID on Header Click, Accordion
本文介绍了关于头获取股利ID点击,手风琴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用jQuery的手风琴来填充dynatree。我需要我的手风琴div的填充在头部的点击,所以这就是为什么我试图抓住DIV ID。当我点击扩展分区,而不是头里面这个jQuery工作,但只。这是有道理的,因为我的事件。常见的点击。
I'm using Jquery accordion to populate a dynatree. I need my accordion div's to populate on click of the header, so that is why I am trying to grab div id. This Jquery works but only when I click inside the expanded div and not the header. Which makes sense because my event is .common click.
$(".common").click(function () {
var currentID = $(this).attr("id");
alert(currentID);
});
<div id="accordion">
<h3>Project Type</h3>
<div id="1" class="common" style="height:150px;">
</div>
<h3>Ammenities</h3>
<div id="2" class="common" style="height:150px;">
</div>
</div>
我需要弄清楚如何我可以在头点击获取DIV ID。手风琴没有起到非常漂亮,如果我我的id和class切换到头部,该事件不火。我已经尝试过使用 $(#手风琴。常见的)。点击
,这无法正常工作或
推荐答案
您可以针对这是一个<$ C $的previous兄弟H3
元素C>。常见元素
You can target the h3
elements which are the previous sibling of a .common
element
$(".common").prev('h3').click(function () {
var currentID = $(this).next().attr("id");
alert(currentID);
});
演示:小提琴
,也可以针对 H3这是
#accordion
元素
$("#accordion > h3").click(function () {
var currentID = $(this).next().attr("id");
alert(currentID);
});
演示:小提琴
这篇关于关于头获取股利ID点击,手风琴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文