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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:24:45+00:00 2026-06-17T16:24:45+00:00

I’m dealing with some pages that are build using ajax calls to the server,

  • 0

I’m dealing with some pages that are build using ajax calls to the server, so I am relying on .on() to attach event handlers to new items.

I was wondering, however, if, when possible, is it more efficient to rely on the old javascript:function() to call a function, whenever the event handler is a click.

Here’s an example.

I get from the server a link element a:

<a href="javascript:doMoreStuff()" class="classThatDoesMore">Do More!</a>

and I insert it in the document like so:

// ajax call and so
$(this).html(response);

To “do more” I then have two ways (there might be other ways but I’m not aware of them, but any suggestion is welcome!):

$(document).on("click",".clssThatDoesMore",function(){ // I need (document)
     // here something will be done
});

or

doMoreStuff(){
    // here something will be done as well
}

As far as I know both solutions are pretty much cross-browser (I’ve tested href="javascript:function()" and it goes back at least to IE8), but in case I’m wrong please let me know!

I was wondering if an excess of .on() “listeners” may pose to much load on the browser, and so if it is better to rely on javascript:function(), or if, on the contrary, .on() does not require much resources at all and having several .on() listeners in the page is not a problem.

PS I’ve abandoned onclick="doMoreStuff()" since in Safari it was not working, while in FF the same exact code was and so was in Safari if done usinge href="javascript:doMoreStuff().

PPS this is not the same old question js v. jquery, to me the point is not which in general terms is more efficient, I would like to understand what’s the best way in which this particular task can be achieved 🙂

  • 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-17T16:24:46+00:00Added an answer on June 17, 2026 at 4:24 pm

    javascript:doMoreStuff() is just as bad, if not worse, than onclick="doMoreStuff()". You have a lack of flexibility, no fallback if JS is not enabled, and the javascript: pseudo-protocol is not even compliant as I understand.

    Let’s forget about efficiency and just focus on the fact that .on is much cleaner. You can separate it out from the html/ajax, and it’s very simple to see what you are doing and change it later.

    As for efficiency, I don’t think you will notice a difference. .on is very slightly less efficient in that the click event has to traverse the DOM tree a bit to figure out whether the event should fire, but that’s very small potatoes.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am using JSon response to parse title,date content and thumbnail images and place
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only

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.