Take the 2-minute tour ×

I want to wrap the following code into a function using jQuery and call that function from inline (eg: onclick, onchange etc.).

function some_function() {
   alert("Hello world");

Called by (example):

<input type="button" id="message" onclick="some_function()" />

This question is simple for a reason. I can't seem to find a proper jQuery how-to.

  • Should I wrap that function into a jQuery $(document).ready() ?
  • Should make a normal javascript function and use $(document).ready() in that function?
share|improve this question
The reason why you don't find how-tos explaining how to do it is because inline events are not the best way to do event handling, and jQuery has made the cross browser compatibility reason obsolete. –  Yi Jiang Aug 27 '10 at 10:31
add comment

1 Answer

You should not use that inline event handler to go with jQuery.

Use unobtrusive code:

function some_function() {
  alert("Hello world");

share|improve this answer
add comment

Your Answer


