1

I always use jquery event like:

$(element).on('click', function() {
    DoSomething();
});

But other way is exists - add "onclick" attribute to html element:

<button onclick="DoSomething()"></button>

Which way is better and why?

6
  • 1
    Most people will point to first way due to separation of concerns Commented Oct 21, 2014 at 6:03
  • 2
    First one looks easier to maintain and more flexible Commented Oct 21, 2014 at 6:03
  • See this: stackoverflow.com/questions/12627443/jquery-click-vs-onclick Commented Oct 21, 2014 at 6:04
  • 2
    duplicate of jQuery.click() vs onClick Commented Oct 21, 2014 at 6:04
  • the first way makes it easier to maintain code; it is recommended since it provides good modularity. Commented Oct 21, 2014 at 6:06

1 Answer 1

1

It is best to use the jquery because you want to separate your layout, functionality, and styling for easier readability and editing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.