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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:03:04+00:00 2026-06-06T10:03:04+00:00

I am making a question and answer page similar to Stackoverflow, though I am

  • 0

I am making a question and answer page similar to Stackoverflow, though I am hand writing the code, basically for fun.

I am writing an ajax post that happens on click, which brings in a supposedly clickable div. The AJAX post looks something like this:

function answerQuestion(){
    $('.answerQuestion').click(function(){
        var user_id = $('#user_id').val();
        var q_id = $('.q_id').val();
        var answer = CKEDITOR.instances.editor1.getData();
        if(answer && q_id && user_id){
            $.post("scripts/questions/answerQuestion.php", {user_id : user_id, q_id : q_id, answer : answer}, function(answerThisQuestion) {
                $('.answerTotalCont').last().css('border-bottom', '1px dashed #444');
                $(answerThisQuestion).hide().appendTo('.allAnswers').slideDown(1000, 'easeOutExpo');
            });
        }
    });
}

When the post appends the data, it brings in a clickable div called “answerAskButton”. This div has the possiblity of being on the page already when you load, and will always load after the AJAX call.

This ‘button’, when clicked makes a different AJAX post, basically for comments. Here is the code for it:

function submitComment(noType) {
    //$('.answerAskButton').click(function(){
    $('.answerAskButton').live("click", function(){
        //GET ALL OF THE VARIABLES - THIS CODE IS FUNCTIONING PROPERLY - THIS IS JUST ABRIDGED TO SHOW SMALLER CODE
        $.post("scripts/questions/postComment.php", {details : details, user_id : user_id, q_id : q_id, qora : qora, a_id : a_id}, function(postComment) {
            noComment.slideUp(1000, 'easeOutExpo');
            $(postComment).hide().appendTo(newComment).slideDown(1000, 'easeOutExpo');
            $('.questComment').val(noType);
        });
        $('.questCommentsCont').slideUp(300, 'easeOutCirc');
        $('.questComment').val(noType);
    });
}

And these are both called on document load.

The problem is: When I make the answerQuestion() post, after it loads the AJAX data and shows a new clickable button, That button (answerAskButton) is no longer clickable, though, the other buttons that were obviously onload are still working.

I heard .live() was the way to fix this, but as you can see, it is not working for me.

any Advice?

UPDATE::
I have updated the code .on() instead of .live(), though it is still not working. If you would like to take a look at my code, the Login is here (username: public, password: public) and the page in question are any of these Question Pages which you can find on the Q&A page.

The script we’re talking about is called questions.js which is viewable through firebug or element inspector

  • 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-06T10:03:11+00:00Added an answer on June 6, 2026 at 10:03 am

    As you’re using jQuery 1.7.x then instead of live() use .on() like:

    $(document).on('click', '.answerAskButton', function(){
      // your code
    })
    

    Because live() has been deprecated.


    Note

    Syntax of .on() for delegate event:

    $(container).on(eventName, target, handlerFunction)
    

    Here, container points to a Static-element that belong to DOM at page load.


    Full code

    function submitComment(noType) {
       $(document).on('click', '.answerAskButton', function(){
            //GET ALL OF THE VARIABLES - THIS CODE IS FUNCTIONING PROPERLY - THIS IS JUST ABRIDGED TO SHOW SMALLER CODE
            $.post("scripts/questions/postComment.php", {details : details, user_id : user_id, q_id : q_id, qora : qora, a_id : a_id}, function(postComment) {
                noComment.slideUp(1000, 'easeOutExpo');
                $(postComment).hide().appendTo(newComment).slideDown(1000, 'easeOutExpo');
                $('.questComment').val(noType);
            });
            $('.questCommentsCont').slideUp(300, 'easeOutCirc');
            $('.questComment').val(noType);
        });
    }
    

    Tip

    It would be better to use some other Static-element instead of document for .on() delegation.

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

Sidebar

Related Questions

I apologize for making my first question not the hard-hitting code-related question I was
Basically the question is, Why are NONE of the changes I've been making in
Making a simple three question PHP quiz. Each question is displayed on a page
Basically, i am trying to create a web page that utilises jquery in order
I am making a page where users can answer questions (using radio buttons) about
I found and am using the following stackoverflow question and answer here . I'm
Im Making a question for a website and would like the the correct /
I asked a question about making a greatest n per group type query yesterday
My focus in this question is making HTML5 games. The aim is to help
Totally n00b question, Im making my first ASP.NET website, with the added twist of

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.