[英]How to set the content of an alert in javascript as per the element which is clicked?
[英]How to set $(this) as the clicked element
在下面的代码中:
// submit an item
$(document).on("click", ".match-item", function(event) {
// how to set $(this) == $('.match-item') clicked?
});
我正在寻找检索$(this)
作为单击项,而不是document
本身。 我该怎么做?
这更多是澄清而不是答案。
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>
怎么样
$('.match-item').click(function() {
//your code with $(this) here
});
我很确定$(this)
将引用类match-item
的元素
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.