I want to access the id of button , when i write the PHP variable the javascript code create error "Undefined" value.
function update_profile(){ $(function() {
var element = $(this);
var update_id = element.attr("id");
var infoo = 'updated_id=' + update_id;
document.getElementsByClassName('test')[0].innerHTML=infoo;
});
}
button code:
<button data-toggle="modal" data-target=".bs-example-modal-lg" onclick="update_profile()" class="btn-xs btn-warning " id='<?php echo $user_rec[1]; ?>' >Update</button>
$(function() {and closing it});$(function() { })and changedocument.getElementsByClassName('test')[0].innerHTML=infoo;to$(".test").first().html(infoo);or better:$(function() { $(".btn-warning").on("click",function() { $(".test").first().html(this.id); }); });