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 7787181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:34:52+00:00 2026-06-01T20:34:52+00:00

As the title may be slightly ambiguous or not clear, I’ll first explain what

  • 0

As the title may be slightly ambiguous or not clear, I’ll first explain what I mean by the two methods. In my HTML/JS code, I mix two ways of attaching events to my html elements: (1) what I call “static”:

<input name="abc" class="def" id="xyz" onclick="do_something"/>

and (2) what I call “dynamic”:

<input name="abc" class="def" id="xyz" />

with

$(document).ready(function() {
    $('#xyz').click(function() { do_something; })
});

Note that this is not a real code, just something to present as an example. I don’t have to use jquery either, the same could be achieve with simple

document.onload = function() {
    document.getElementById('xyz').onclick = function() { do_something; }
}

Usually if the logic is quite simple (e.g. enable/disable on element on click of another), I would use static method. If the logic is more complicated, I would use dynamic one. Of course, I can also use static method with onclick="function_call()" – and put all the complicated logic into this function, although this is something I may have left in the code from legacy days (from years ago).

Now, I have met people that would swear by one of the methods and deride anybody that would use the other, claiming that the other method is wrong/difficult-to-read/slower/add-your-own-explanation. HoweverI have not found any really good reason to always stick with one method and keep mixing these up. Am I missing something or is there really no good reason to stick with one method?

  • 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-01T20:34:54+00:00Added an answer on June 1, 2026 at 8:34 pm

    My practice is to follow the rule of least surprise.

    If my page is 99% HTML and just 1 or 2 lines of Javascript then I use inline events <div onclick=""> to minimize the amount of fluff in the page due to addEventListener baggage.

    If my page is too complex with too many elements and if separation of behavior will cause large chunks of getElementById or $('.tree') sections, which actually inhibits resadability (therefore increases surprise level) then I also use inline event. How and why

    Otherwise I use the expected separation of structure and behavior rule.

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

Sidebar

Related Questions

Ok Title may not be clear so let me explain. I have 2 classes,
The title may not really explain what I'm really trying to get at, couldn't
my title may not be clear. But basically what I want to do is:
The title may be long, let me explain what I mean. I won't give
Ok, the title may not be the most descriptive. It's easier to explain with
I may of got the Title slightly wrong but basically, I have two cells.
my title may not explain what I am looking for, this is my current
the post title may not explain fully, but here is what I am hoping
Title may be confusing, but here's explanation with code. Based on some conditions, I
The title may be a bit ambiguous, but I couldn't think of a better

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.