I would like to get the current element (whatever element that is) in an HTML document that I clicked.(我想在单击的HTML文档中获取当前元素(无论是哪个元素)。)
I am using:(我在用:)
$(document).click(function () {
alert($(this).text());
});
But very strangely, I get the text of the whole(!) document, not the clicked element.(但是非常奇怪的是,我得到了整个文档的文本,而不是单击的元素。)
How to get only the element I clicked on?(如何仅获取我单击的元素?)
Example(例)
<body>
<div class="myclass">test</div>
<p>asdfasfasf</p>
</body>
If I click on the "test" text, I would like to be able to read the attribute with $(this).attr("myclass"
) in jQuery.(如果单击“测试”文本,我希望能够在jQuery中使用$(this).attr("myclass"
)读取属性。)
ask by user1145216 translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…