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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:26:21+00:00 2026-05-27T11:26:21+00:00

When loading content inside of a modal box or lightbox, is it better to

  • 0

When loading content inside of a modal box or lightbox, is it better to hook up needed events and scripts through the use of jQuery.on(), or have it load with the content by a script tag?

For example, with the .on() solution:

$('#blah').on('load', function() {
    $('#something').click(function() { alert('Hi'); });
});

And then when the modal box was loaded, it would call $('#blah').trigger('load')

Or, just simple have the the script loaded in with the HTML as in:

<div id="blah">
    <a href="#" id="something">Something</a>
</div>
<script src="/js/blah.js"></script>

With blah.js containing the javascript code above involving setting up the click event on #something. I’ve used the .on() method for a while, but I wasn’t sure if this was the best way to handle this.

  • 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-05-27T11:26:21+00:00Added an answer on May 27, 2026 at 11:26 am

    Argument for the script inclusion solution

    The on solution is ugly and involved. It requires more code than the simple script inclusion, and mixes up concerns between the load handling code (which is presumably somewhere else) and the lightbox contents. Why should that code know about the ids of elements inside the lightbox?

    Argument for the on solution

    It involves one less HTTP request and so will probably be faster.

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

Sidebar

Related Questions

I have some content that I am loading using jquery ajax. The content has
I am loading content into a page with ajax that will have live click
I am loading an XML file using jQuery $.get. after loading the content, i
I'm using jQuery address to enable loading specific content from other pages and to
I am loading a jQuery qtip on hover (as it usually works). Inside this
I have 2 jquery scripts and I'm not sure exactly how to combine them.
Hi I have a JQuery Ui (jquery-ui-1.8.13.custom.min.js) inside a Dialog. When I start typing
I have content that I'm loading using an AJAX call and displaying the HTML
Loading an external php file with jquery is actually easy. I simply use the
I have used a tutorial http://www.devcurry.com/2010/06/load-page-dynamically-inside-jquery-ui.html to dynammically load an aspx page into a

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.