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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:51:42+00:00 2026-05-20T17:51:42+00:00

I have a set of nested elements like such. <div id=master> <span id=num-1 class=num></span>

  • 0

I have a set of nested elements like such.

<div id="master">
    <span id="num-1" class="num"></span>
    <span id="num-2" class="num"></span>
    <span id="num-3" class="num"></span>
    <span id="num-4" class="num"></span>
</div>

And I have the following script

$( document ).ready( function() {
    $( '#master > span.num' ).click( function() {
        q = $( "span[id*=num-']" ).attr( "id" );
        $( '#master' ).html( '&nbsp;' ).load( 'www.someurl.com/?rating=' + q );
    });
});

The load function returns a completely new set of span elements for inside the div. Problem is that I can’t seem to figure out how to get this to work past the first time I click one. Since the click is tied to the spans and the spans get replaced, I understand that they no longer have a script tied to them, but I haven’t been able to figure out how to get this to re-tie on the fly. I’m super new to jquery and javascript so any help would be appriciated.

All my experiments with using .live() have merely rendered my script useless. Help?

  • 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-20T17:51:42+00:00Added an answer on May 20, 2026 at 5:51 pm
    • DEMO: https://so.lucafilosofi.com/re-tying-a-the-jquery-click-dynamically-after-replacing-the-element/

    EDITED: as suggested by Beejamin

    $( function() {
        $('#master').click( function(e) { 
        if (e.target.className.indexOf('num') !== -1) {
            var num = e.target.id.split('-')[1]; //this give you # instead of num-#
            $(this).load( 'rating.php/?rating=' + num );
          }  
        });
    });
    

      $(function() {
        $('.num').live('click',function() {
         var num = this.id.split('-')[1]; //this give you # instead of num-#
            $('#master').load( 'rating.php?rating=' + num );
              return false;
        });
    });
    

    I suppose you are trying to do a rating system? just for sake my PHP file look like this:

    <?php
      if (isset($_GET['rating'])) {
      $rating = (int) $_GET['rating'];
      for ($i = 1; $i < 5; $i++) {
        $a .= "<a id='num-{$i}' class='num".($rating >= $i ? ' rated' : '')."'></a>";
      }
      echo $a;
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To set up nested resources in Rails, I have seen example routes given like
I have a menu implemented using a set of nested accordions, 1 and 2
I a template, I have five DIV elements underneath each other on a HTML
I have a set of nested Ant build files, and I need to control
We have set up a system where notifications get sent to a user with
I have set a canvas' background to an image of a company logo. I
I have set up transactional replication between two SQL Servers on different ends of
I have set up a version control system using TortoiseSVN at my home to
I have set up a Django application that uses images. I think I have
I have set the FlushMode property on an NHibernate session to FlushMode.Never, but when

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.