I want to get element by class and data attribute and add disabled to this element
<button type="button" data-pid="23" class="add " tabindex="0">click me</button>
$(".add").on("click", function(e) {
e.preventDefault();
var pid = $(this).attr('data-pid');
$('.add[data-pid="'+pid+'"]').attr("disabled", "disabled");
});
this code not work
thanks
e.preventDefault()prevents the default action of the element. There is no default action of a button oftype="button". If the button were oftype="submit", thene.preventDefault()would prevent the form from submitting. So,e.preventDefault()is not necessary in your example