Is it possible to add a onclick
event to any button by jquery or something like we add class?
function onload()
{
//add a something() function to button by id
}
Is it possible to add a onclick
event to any button by jquery or something like we add class?
function onload()
{
//add a something() function to button by id
}
Yes. You could write it like this:
$(document).ready(function() {
$(".button").click(function(){
// do something when clicked
});
});
Yes. Something like the following should work.
$('#button_id').click(function() {
// do stuff
});
Calling your function something
binding the click
event on the element with a ID
$('#id').click(function(e) {
something();
});
$('#id').click(something);
$('#id').bind("click", function(e) { something(); });
Live has a slightly difference, it will bind the event for any elements added, but since you are using the ID it probably wont happen, unless you remove the element from the DOM and add back later on (with the same ID).
$('#id').live("click", function(e) { something(); });
Not sure if this one works in any case, it adds the attribute onclick
on your element: (I never use it)
$('#id').attr("onclick", "something()");
Documentation