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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:13:43+00:00 2026-06-12T08:13:43+00:00

I want to know why is that my javascript functions won’t work if my

  • 0

I want to know why is that my javascript functions won’t work if my html tag is from the php script??

Here’s my jquery code:

$(function () {

//functions don't work

    $('ul li:gt(4)').hide();

    $('.prev').click(function() {
        var first = $('ul').children('li:visible:first');
        first.prevAll(':lt(5)').show();
        first.prev().nextAll().hide()
    });

    $('.next').click(function() {
        var last = $('ul').children('li:visible:last');
        last.nextAll(':lt(5)').show();
        last.next().prevAll().hide();
    });

//end of functions don't work

    $('.load').click(function() {
        $.ajax({
            url: 'load.php',
            success:function(data){
                $('#paging-container').html(data);
            }
        });
    });

});

Here’s my html code:

<input class="load" type="button" value="Load">
<div id="paging-container">

</div>

And here’s my php script:

 <?php  
    echo '<ul>';
    for($i=1;$i<=50;$i++){
        echo '<li>'.$i.'</li>';
    }
echo '</ul>
<a class="prev">prev</a> | <a class="next">next</a>';
?>
  • 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-12T08:13:44+00:00Added an answer on June 12, 2026 at 8:13 am

    For the type of jQuery you’re using, the HTML tags must exist in your page already at the time you are running the initial jQuery. As it is, they do not exist and thus no event handlers are attached to them.

    You have a couple choices to correct that:

    1. You can use the dynamic form of event handlers with .on()
    2. You can install the event handlers AFTER you add the objects to the page.

    Using the dynamic form of .on() would look like this:

    $("#paging-container").on('click', '.prev', function() {
        var first = $('ul').children('li:visible:first');
        first.prevAll(':lt(5)').show();
        first.prev().nextAll().hide()
    });
    
    $("#paging-container").on('click', '.next', function() {
        var last = $('ul').children('li:visible:last');
        last.nextAll(':lt(5)').show();
        last.next().prevAll().hide();
    });
    

    Here the event handler is actually attached to #paging-container and it uses delegated event handling to catch the events that happen on child objects. This will work even if child objects are added/removed after the event handler is installed as long as #paging-container itself is not destroyed.

    See this post for a general description of how the dynamic flavor of .on() works.

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

Sidebar

Related Questions

I want to know what is necessary to create a PHP script that can
I want to know Id update panel that initial a request in JavaScript .I
i want to know that when we want to use push notification service.From where
Like a lot of you guys know that the javascript functions or methods can
I want to call some javascript functions after all ajax calls. I know how
I know that a javascript function is perfectly capable of calling other functions. I've
I want to know that is there any better method to do : var
I want to know that how to follow a page on Twitter using android
I want to know that how one should proceed in building animated splash screen.
I want to know that, is something like this, possible? : #test{ background-color: red;

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.