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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:01:47+00:00 2026-05-24T03:01:47+00:00

I’m using a piece of JS twice for two, different yet the same, events.

  • 0

I’m using a piece of JS twice for two, different yet the same, events.

To make it more simple, let’s say I’ve got:

<script type="text/javascript">
    $(function(){
        $(".iframe").load(function(){
               $(this).contents().find("form").delegate(".clickThisCheckBox","click",function(){
                alert(this)
            })
        })
    })
</script>

<div class="tabs">
    <ul class="tabs-nav">
        <li><a href="#products">Products</a></li>
        <li><a href="#accessories">Accessories</a></li>
    </ul>
</div>

<div class="content">
    <div id="products">
        <iframe class="iframe">
            <form action="?" method="post">
                <input type="checkbox" name="checkBox1" class="clickThisCheckBox" />
            </form>
        </iframe>
    </div>

    <div id="accessories">
        <iframe class="iframe">
            <form action="?" method="post">
                <input type="checkbox" name="checkBox2" class="clickThisCheckBox" />
            </form>
        </iframe>       
    </div>
</div>

This a more simplified version than what I’ve got, but exactly the same concept.

So when the page loads, you click the checkbox in the open tab, and you’ll successfully get the alert box with the object. When you click the next tab and try to click the checkbox, nothing happens.

There is no AJAX or separate loading going on. Everything gets rendered on the initial page load. Both iframes are loaded at the same time and you access a different once by switching to a different tab.

Does the JS need to be in a function and ran each time a tab is clicked? Can’t seem to wrap my finger around this one.

Update: Narrowed it down to it absolutely being that the JS only get’s run once, so only the first iFrame in the first tab gets all the correct variables and events bound to the elements.

Update: Seemed to have figured it out. While continuing to use iFrames, I had to throw all of my JS into a function and run it on $(".iframe").load() and whenever a new tab is click, for example, $(".nav-cont li a").bind("click",function(){ //run the javascript })

  • 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-24T03:01:48+00:00Added an answer on May 24, 2026 at 3:01 am

    If you want to bind load event to two identical iframes:

    $("div.contents").delegate(".iframe", "load", function(){
       alert('one of the iframes loaded');
    });
    

    One handler function handles “load “event for both iframes.

    P.S. UPDATE
    You can’t use iframes the way you explain in comments. Simply use divs instead and set overflow:hidden; If the intent is to limit the display size of that specific area with data – set this in css file:

    .form_container{width:500px;heigth:500px;overflow:hidden;}
    

    Your html then will be:

    <div class="tabs">
        <ul class="tabs-nav">
            <li><a href="#products">Products</a></li>
            <li><a href="#accessories">Accessories</a></li>
        </ul>
    </div>
    
    <div class="content">
        <div id="products">
            <div class="form_container">
                <form action="?" method="post">
                    <input type="checkbox" name="checkBox1" class="clickThisCheckBox" />
                </form>
            </div>
        </div>
    
        <div id="accessories">
            <div class="form_container">
                <form action="?" method="post">
                    <input type="checkbox" name="checkBox2" class="clickThisCheckBox" />
                </form>
            </div>
        </div>
    

    And js will be:

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $('form').find(':checkbox').click(function(){
            alert('something got clicked');
        })
    })
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
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 reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.