Reputation: 15892
I have been using Jquery alot lately an was wondering if I should use listeners or functions for my clicks.
Normally I do the following:
<head>
<script type="text/javascipt">
function buttonclicked() {
alert("You Clicked it");
}
</script>
</head>
<button onclick="buttonclicked()">Click Me</button>
Upvotes: 2
Views: 121
Reputation: 413856
Reasons that it's better to use the jQuery event mechanism and not the "intrusive" onfoo element attributes:
Overall, if you're going to use jQuery, dive in and really use it.
Upvotes: 2
Reputation: 57968
i think its more efficient to do what you did in your example.
Also, i wouldnt do that since it is not that much more efficient that it would matter, and it makes for ugly code. Also its better to separate your js from your html.
So please dont do what you did in your example unless you have a very good reason
Upvotes: 1
Reputation: 490453
Benefits of using listeners also allow you to separate your markup and JavaScript.
Upvotes: 2