-1

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

dumbass
27.2k4 gold badges43 silver badges77 bronze badges
asked May 12, 2014 at 7:47

5 Answers 5

0

you just need keep your function simple like this .

function call(id){
alert(id);
}

It will work for you !!

answered May 12, 2014 at 7:50
Sign up to request clarification or add additional context in comments.

Comments

0

It's a normal js function called from an inline click handler so:

function call(id){
 // do some stuff using id
}
answered May 12, 2014 at 7:49

Comments

0

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){}
answered May 12, 2014 at 7:50

Comments

0

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
 }
});
answered May 12, 2014 at 7:53

Comments

-1

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.

answered May 12, 2014 at 7:55

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.