![](/img/trans.png)
[英]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.