if I have a button that has onclick event like that:
'<a href="" class="ui-btn" onclick="call('+item.id+')">Aprobar</a>'
How I have to define this function call?
$ function call(id){
)}
Thank you
5 Answers 5
you just need keep your function simple like this .
function call(id){
alert(id);
}
It will work for you !!
Comments
It's a normal js function called from an inline click handler so:
function call(id){
// do some stuff using id
}
Comments
only call the function name without $ . i think $ is for jquery and it dose not need for regular javascript function
function call(id){
}
but it is best practice to write like this
var call = function(id){}
Comments
If you're declaring the function within another such as jQuery's ready function, you will need to scope the function in the window level for it to be globally available.
Javascript:
$(document).ready(function(){
window.call = function(id){
// Do something
}
});
Comments
Do it in all jQuery, refer to below code.
remove onclick call and give id, like below :
'<a href="" id="ui-btn1" class="ui-btn">Aprobar</a>'
Then add onclick event using jQuery :
<script>
$(document).ready(function(){
$("#ui-btn1").click(function(
var buttonId = $(this).attr('id');
alert(buttonId);
));
});
</script>
If you wan to bind click event to button by its class name then use below selector
$("#ui-btn1").click(function(
You can select button using various selectors, please see this.