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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:49:45+00:00 2026-05-11T07:49:45+00:00

I’ve just started looking at JQuery. I don’t have any AJAX in my web

  • 0

I’ve just started looking at JQuery. I don’t have any AJAX in my web application at present.

My existing JavaScript in my HTML looks like:

<form ...> <p>Find what? <input ...></p> <div class='ButtonArray'>   <a href='AddRecord.ASP&amp;Action=ADD'>ADD</a>   <a href='#' onClick='return MyFormSubmit();'>FIND</a> </div> </form> 

This displays Buttons for [Add] and [Find]. For Find it is necessary to Submit the form, and I use MyFormSubmit() which validates the data, adds a visual effect to the page, and then POSTs the data.

I could add a CLASS or ID to the for the Find button and in JQuery I could write something like:

$(function() {   $('.MySearchButtonClass').click(function() {     // validate and process form here   }); }); 

At my ‘novice’ stage of understanding with JQuery I don’t get why I would do it this way

My old way identifies the Method near the object. There may be a risk that the JS has not loaded before the user presses the button (is there? The LOAD for the JS is right at the top of the page).

The JQuery Document Ready method won’t be activated until the document is loaded (which I assume guarantees that the JS is all present and ready to be run?), but it moves the code to a separate part of my HTML file – so when I see the MyButtonArray DIV in the HTML source it isn’t obvious to me which objects have methods, and which do not.

Can you please help me understand what my options are and the benefits / gotchas that I should look out for?

Edit: I’m comfortable that DOM manipulation – such as a LightBox that can appear when any thumbnail with class ‘LightBoxThumb’ is clicked – would use Unobtrusive Javascript.

However I am struggling to persuade myself that a button that has a specific action should have its method applied in that way. (I certainly wouldn’t put any code on the button other than a single function call to something ‘elsewhere’, but to my mind that is my best clue as to what that button does, and layers of Unobtrusive Javascript may make that much harder to determine.)

Edit2 – Accepted Answer

I’ve taken Russ Cams answer. It describes Unobtrusive Javascript in a way that has been helpful to me in understanding more about how & when that should be used.

For the moment (may change when I have more experience!) I’ll stick with an OnClick event for a single, non-changing, action on an object as I feel that will be easier for me to debug – and diagnose if problems arise. For ZebraStripes on a table that allows click on heading column to sort (and situations of that type) I can see the benefits of the Unobtrusive Javascript approach

Russ’s final comment was particularly helpful, repeated here:

‘@Kristen – You’re right, like a lot of programming topics, there is more than one approach and people will vehemently stand by their beliefs! If we’re talking about a single method for a single button, I totally understand where you’re coming from…

If we’re talking about lots of JavaScript, with same function calls for more than one element, different function calls for different methods, etc. I think that it would be more difficult for oneself to mix inline and unobtrusive approaches, and it would be better to adopt one or the other approach’

  • 1 1 Answer
  • 3 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. 2026-05-11T07:49:46+00:00Added an answer on May 11, 2026 at 7:49 am

    Unobtrusive JavaScript is the main driver for separating JS code from markup

    • Separation of functionality (the ‘behavior layer’) from a Web page’s
      structure/content and presentation
    • Best practices to avoid the problems of traditional JavaScript programming (such as browser inconsistencies and lack of scalability)
    • Progressive enhancement to support user agents that may not support
      advanced JavaScript functionality

    With the code in document.ready, it will not execute until the DOM has loaded and before the page contents are loaded

    From Learning jQuery

    With $(document).ready(), you can get your events to load or fire or whatever you want them to do before the window loads.

    You may want to take a look at jQuery in Action, I’d highly recommend it. You can sample Chapter 1 and Chapter 5 on the book’s homepage. I think doing so may provide further insight into why separation can work well.

    Finally, have a look at this question which has answers that detail how you would find the event listeners on a DOM node.

    EDIT:

    Some thoughts which may persuade you why unobtrusive JavaScript can be a good idea.

    Imagine that you have a function bound as an event handler for the same event raised on each of a number of elements –

    • Would it be easier to find out which elements call that function to handle an event when the declaration is inline in each element, or the declaration is in one place, outside of the markup?

    • What if you want to add to the elements that call that function when the event is raised on each of them? Would it be easier/better to add the event handler inline to each element or to change the code in one place?

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have thousands of HTML files to process using Groovy/Java and I need to
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small

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.