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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:19:54+00:00 2026-06-15T14:19:54+00:00

In my code i’m using the following two lines from a previous question of

  • 0

In my code i’m using the following two lines from a previous question of mine here.

$(this).removeClass('page larger').addClass('current');
$(this).siblings().removeClass('current').addClass('page larger');

If I place these anywhere outside success: It works fine. But if I place them inside success: they wont work. I need them to work only on success:. How can I solve this?

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>PHP, jQuery search demo</title>
<style type="text/css">
.current{
padding:5px;
border:1px solid #000000;
background-color:white;
cursor:pointer;
}
.page{
padding:5px;
border:1px solid #000000;
background-color:red;
cursor:pointer;
}
</style>

<script type="text/javascript" src="http://localhost/jQuery1.8.3.js"></script>
<script type="text/javascript">
$(function() {

    $('.page').live('click', function() {

       var menus    =($(this).attr("menus"));
       var data            = menus;

        if(data) {

        //alert (data);
        //    // ajax call
            $.ajax({
                type: "GET",
                 url: "pages.php",
                data: data,
                dataType: "json",
               cache: false,
          beforeSend: function(html) {

                    $(".pageLoading").html("Fetching new posts...");

                },
               success: function(page_data){
                    $(".posts").empty();
                    $(".pageLoading").empty();
                    $(".posts").html(page_data['articles']);
                    console.log (page_data['articles']);

                               $(this).removeClass('page larger').addClass('current');
                              $(this).siblings().removeClass('current').addClass('page larger');

              },

          });    
        }
        return false;
    });
    /////////////////////////////////////////////////////////////////////////

});
</script>

</head>
<body>
    <div class="posts">These are the existing posts</div>
    <br />
        <div class="navigation clearfix">
            <div class="menusHolder">
                    <span  menus="in/consumer/p22" class="current">1</span>
                    <span  menus="in/consumer/p19" class="page larger">2</span>
                    <span  menus="in/consumer/p15" class="page larger">3</span>
                    <span  menus="in/consumer/p10" class="page larger">4</span>
            </div>
        </div>
        <br />
        <div class="pageLoading"></div>
</body>
</html>
  • 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-15T14:19:55+00:00Added an answer on June 15, 2026 at 2:19 pm

    The scope of this has changed. If you want to keep a reference to the original element, create a variable at the click scope and the success handler will include it in its closure:

    $(function() {
    
        $('.page').live('click', function() {
    
           var menus    =($(this).attr("menus"));
           var data            = menus;
           var $that = $(this); // <- add this
    
            if(data) {
    
            //alert (data);
            //    // ajax call
                $.ajax({
                    type: "GET",
                     url: "pages.php",
                    data: data,
                    dataType: "json",
                   cache: false,
              beforeSend: function(html) {
    
                        $(".pageLoading").html("Fetching new posts...");
    
                    },
                   success: function(page_data){
                        $(".posts").empty();
                        $(".pageLoading").empty();
                        $(".posts").html(page_data['articles']);
                        console.log (page_data['articles']);
    
                         // change $(this) to $that. success handler is a closure that will include $that
                         $that.removeClass('page larger').addClass('current');
                         $that.siblings().removeClass('current').addClass('page larger');
    
                  },
    
              });    
            }
            return false;
        });
        /////////////////////////////////////////////////////////////////////////
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code sample for my question: IList<TestDataAnimal> testDataFromDb = this.db.TestDataAnimals.Include(t => t.TestType).Include(t => t.Visit).Include(t =>
Code adapted from here : #from 'foo_bar' to 'Foo.Bar' def lower_case_underscore_to_camel_case(self, string): print string
Code below taken from here . * qsort example */ #include <stdio.h> #include <stdlib.h>
Code to create new form instance of a closed form using form name I
Code: NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; BOOL initial = YES; [invocation setArgument:&initial atIndex:2]; Question:
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Code that is untestable really annoys me. The following things make oo-code untestable: global
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code to decode numeric html entities to the UTF8 equivalent character.
This could be a duplicate question, but I have no idea what search terms

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.