Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8321251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:57:09+00:00 2026-06-08T22:57:09+00:00

Is inline event handlers considered a bad practice? For example: <button onclick=someFunction()>Click me!</button> If

  • 0

Is inline event handlers considered a bad practice?

For example: <button onclick=someFunction()>Click me!</button>

If so, what are the disadvantages of using inline event handlers?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:57:10+00:00Added an answer on June 8, 2026 at 10:57 pm

    It’s a bad idea because…

    1. Best practice suggests a clear split between content, style and script. Muddying your HTML with inline JavaScript (or CSS) is not consistent with this.

    2. You can bind only one event of each kind (per element) with on*-style events , so you can’t have two onclick event handlers, for example.

    3. If an event is specified inline, the JS is specified as a string (attribute values are always strings) and evaluated when the event fires. Evaluation is evil.

    4. Functions denoted by inline event handlers must be global (or at least globally accessible), which is rarely the case these days; code is normally namespaced, or encapsulated in modules (thanks, @Sebastian Simon).

    5. Any content security policy (CSP) you’re using would have to be (unwisely) expanded to allow evaluated inline JavaScript.

    In short, handle events centrally via the dedicated addEventListener API, or via jQuery or something.

    [2021 Edit]

    These days, reactive frameworks have somewhat reversed this trend; events in reactive frameworks are normally specified as attributes e.g. in Vue:

    <p v-on:click='foo'>Hello</p>
    

    …where foo is a method of the current component’s data object.

    HOWEVER, this is not true inline event handling; see @colin’s comment under @adnanmuttaleb’s answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it bad practice to write inline event handlers ? For me, I prefer
I am used to using inline events in my websites for example <head> <script>
Okay so, I'm wondering how to unbind an inline onclick event in jQuery. You'd
I'm binding a click event to a hyperlink. Onclick the value (innertext) of the
Inline editing is started using edit formatter action button. If clicked in other row,
I'm trying to migrate from using inline event triggers to using event listeners using
Problem: Creating an Element on a button click then attaching a click event to
asp:Button inside SharePoint Dataview Rows with onclick event does not call C# function. Pull
The problem: making a very simple style switcher with js (without inline event handling).
I'm currently using inline javascript to clear an input text's default value on focus.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.