[英]How to set $(this) as the clicked element
In the following code: 在下面的代码中:
// submit an item
$(document).on("click", ".match-item", function(event) {
// how to set $(this) == $('.match-item') clicked?
});
I'm looking to retrieve $(this)
as the clicked item and not the document
itself. 我正在寻找检索
$(this)
作为单击项,而不是document
本身。 How would I do this? 我该怎么做?
This is more of clarification rather than answer. 这更多是澄清而不是答案。
this
is already referring to the currently clicked element. this
已经指的是当前单击的元素。
$(document).on("click", ".match-item", function(event) { console.log($(this).attr('class')); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="parent"> Parent <div class="match-item">----Click Me</div> </div>
How about 怎么样
$('.match-item').click(function() {
//your code with $(this) here
});
I am pretty sure $(this)
will refer to the element with class match-item
我很确定
$(this)
将引用类match-item
的元素
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.