[英]How do i target a unique id of a button
My goal is to target unique id of a button using jquery. 我的目标是使用jquery定位按钮的唯一ID。
For example 例如
<button id="5412313">Remove</button>
<button id="9882813">Remove</button>
<button id="123123123">Remove</button>
<button id="214343">Remove</button>
<button id="3434343">Remove</button>
<button id="4343434">Remove</button>
Jquery jQuery的
$("#WhatshouldIputInHere?").on("click", function(){
console.log($(this));
});
You can try with remove()
. 您可以尝试remove()
。
$("button").on("click", function(){
$(this).remove();
//$(this).attr('id');
});
Based on your button label i came to know this.you can do anything with your id which i have commanded . 根据您的按钮标签,我开始知道这一点。您可以使用我命令的ID做任何事情。
You can use event
object in the handler function, the code is like this: 您可以在处理函数中使用event
对象,代码如下:
$('button').on('click', function(event) {
alert(event.target.id);
})
$('button').on('click',function(){
console.log($(this));
if($(this).attr('id')=='9882813'){
console.log('button with id '+$(this).attr('id')+'clicked');
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.