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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:14:42+00:00 2026-06-18T12:14:42+00:00

I have a div with class name profile-activity-box which comes as a AJAX response

  • 0

I have a div with class name profile-activity-box which comes as a AJAX response (html code). The AJAX part works perfectly, so no problem there. With ‘works’ I mean that the div is displayed correctly. Now when I put a click event on it, it doesn’t work. I can’t figure out what goes wrong. This is the code:

<div class="row-fluid main-div"> 

    <h3 class="offset1">Laatste activiteit</h3>
    <div class="span8 offset1" id="activity-box-wrapper"></div>

</div>
<script type="text/javascript">

    $(document).ready(function() {
        var id = <?php echo $user['User']['id']?>;
        console.log(id);
        $.ajax({

                type: "POST",
                cache: false,
                url: '/users/getCheckins',
                data: "id="+id,
                success: function(resp) {
                    //console.log(resp);
                    $('#activity-box-wrapper').html(resp);
                },

                error: function(e) {
                    console.log("Server said (error):\n '" + e + "'");
                }
        });
            // this works! So the element is defined!
        console.log($('.profile-activity-box')); 
            // but this does not !
        $('.profile-activity-box').on('click',function(){ 
            $(this).next().slideToggle(100);
            console.log("hello!");
        });
    });
</script>

This is the AJAX response before someone asks me to post it:

echo "<div class='profile-activity-box'>";
echo "<div class='span6'>";
echo "<img src='/img/gf80x80.jpg' alt='' />";
echo $value['Game']['title'];
echo "</div>";
echo "<div class='span3 offset3' style='padding: 30px;'> ";
echo "<img src='/img/thumbsup.png' alt='likes' />";
echo "<span class='like-count'> 2 </span>";
echo "<img src='/img/messagebubble.png' alt='comments'". 
      "style='padding-left:30px' />"; 
echo "<span class='comment-count'> 4</span>";
echo "</div>";
echo "</div>";
echo "<textarea style='display:none;' class='profile-comment-box' rows='3'".
     "placeholder='plaats een comment :)'></textarea>";

Once again, this whole thing is displayed correctly and is also defined at the time I use the click event. What am I doing wrong here? Thanks.

  • 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-18T12:14:43+00:00Added an answer on June 18, 2026 at 12:14 pm

    You can only add handlers to elements already available.

    But your .profile-activity-box is not there before ajax response.

    To overcome, this situation, we use jQuery on.

    We apply handler to already present parent element (#activity-box-wrapper in this case) and when we click at parent, we check if that was on .profile-activity-box too.

    $('#activity-box-wrapper').on('click','.profile-activity-box',function(){ // but this does not !
        $(this).next().slideToggle(100);
        console.log("hello!");
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following html (inside ASP.NET Repeater): <div class=team_member> <a class=teamMemberLink href='<%# Profile.aspx?uID=
I have many DIV with the same class name, let save wmplayer. I want
If I have 10 items, with the class name keyword : <div class=keyword></div> How
I have a form element defined as: <div class=field> <div class=name> <label for=User_LastName> Last
I have something like the following <div id=container> <ul id=name_list> <li class=name> <input type=hidden
I have a div class named switch control which has a div class named
i have my html something like this... <div class = content> <div class =
I have the following code: <?php if (!$user) { ?> <div class=fb-login-button data-perms=email,user_birthday,publish_stream>Login with
Hi guys i have the following code which is part of the Twitter's bootstrap's
I have something like this currently: <div class = className style = position: absolute;

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.