How to get the id of the element clicked using jQuery這個問題的答案是獲得點擊元素的id。如何獲取點擊區域的ID,但不是父級ID?
但它給出了所有的ID。
例如
<div id="major">
<div id="two"> </div>
</div>
當點擊DIV two
我想要得到的id
僅一two
。但是下面的腳本也會給出父母身份。
$("body").on('click','div',function()
{
alert(this.id);
}); //It alerts the two and major. But i want two only.
爲此,我試圖把一些未申報的功能,它給了我期望的結果。例如
$("body").on('click','div',function()
{
alert(this.id);
mkh(); #undeclared function
});
是否有任何inbuild方法來做到這一點。 JS Fiddle