Say for example, using javascript i would normally call a method like this
<a href ="" onclick="javascriptMethod()">Link</a>
and implement the method like this
<script type="text/javascript">
function javascriptMethod(){
//codes
}
</script>
For some reaon on most jQuery documents all I can find is
$("").click(function(){
//codes
});
Can we not make onclick call on jQuery?
CLEARIFICATION: Instead of $().click I need to call the method for the itself due to existing div array which I cannot change. I know how to do it on JavaScript and is quite easy. The question is, can I not call jQuery method for the an element like <img onclick="jQueryMethod" /> ?
I need to pass a value to the method, thats the most important bit. Since the elements are in an array, i cannot figure out which element[x].
onclickand all the other inline events are an old and intrusive way to register events. That’s why people don’t use them anymore when writing modern HTML/JavaScript.Some advantages of registering them via JavaScript instead of using inline events is that you can call functions that are not in the global scope and use closures to have non-global variables available which were defined outside the event function. It also causes a cleaner structure since you don’t mix JavaScript with HTML.
You also have the advantage that you can easily bind a function to lots of elements via e.g. a class selector:
$('.someclass').click(someFunction);