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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:09:56+00:00 2026-06-07T07:09:56+00:00

When the document is ready, I’m fetching some datas from the server through post

  • 0

When the document is ready, I’m fetching some datas from the server through post request and I’m filling it in the HTML as tags by append. When you click that tag, a comment textarea will be displayed. When you click in the document section, the textarea will be closed. The problem here is I can’t enter the text in the textarea, when I click inside, it is hiding. I tried using event.stopPropagation() but no use.

Here is my jquery code:

$.post("/person/keywords/get/", function(data){
    for(i=0; i<data.length; i++)
    {
        count = count + 1;
        $(".keywords-set").append('<div class="keyword-item"><span class="keyword" id="keyword-'+count+'">'+data[i]+'</span><textarea class="comment" id="comment-'+count+'"></textarea></div>');
    }
});

$(".keywords-set").on('click', "[id^=keyword]", function(event) {
    event.preventDefault();
    i = $(this).attr("id");
    i = i.split('-').pop();
    $("#comment-"+i).show();
    return false;
});

$(".comment").click(function(event) {
    event.stopPropagation();                     
});

$(document).click(function() {
    $(".comment").hide();
});

For complete HTML and javascript code, please check here: https://gist.github.com/3024186

It is working in jsfiddle
but not in my localhost. Could you tell the reason, why is it so?

Thanks!

UPDATE

I’ve also tried this

$(".keywords_set").on('click', ".comment", function(event) {
    event.stopPropagation();
});

event.stopPropagation() is not working for HTML elements updated through ajax. But is working for normal(already given) elements.

  • 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-07T07:09:57+00:00Added an answer on June 7, 2026 at 7:09 am

    When doing this:

    $(".keywords_set").on('click', ".comment", function(event) {
    

    You must understand that you’re catching the event in the element “.keywords_set”, and there you will be checking if it bubbled up through “.comment”

    This means that any other “click” events set between “.keywords_set” and “.comment” will also activate.

    doing stop propagation or returning false will only take affect from the bubbling of “.keywords_set” to the document.

    You can do this:

    $(document).click(function() {
       if($(".comment:hover").length==0){
          $(".comment").hide();
       }
    });
    

    Edit: reply to: “Hey, that code works, I don’t know how you are doing it by mentioning .comment.length could you be more descriptive about that?”

    When you do any jquery selector, an array is returned. so if you do $(".comment") all html nodes with the class “.comment” will be returned to you in a list [obj1, obj2, …, objn]

    When you do $(".comment:hover") you are asking jquery to select you any element with the class “comment” which also have the mouse currently on top of it. Meaning if the length of the list returned by $(".comment:hover") is bigger than zero, then you caught a bubble from a click in a “.comment”.

    Although either returning false or stoping propagation should also work. (dunno why in your case it is not working, although i didn’t look much at the full code)

    Edit 2:

    i was lazy to read the full code. but when you are setting the click event for the comment, the comment doesn’t exist yet. so the new comment you are adding will not be be caught by your click handler. add it inside the ajax callback and it will work 🙂

    Edit 3: one more thing:

    you are not getting side effects because the click even you are re-defining only has the the stop propagation, but you should add the stop propagation before returning false in the

    $(".keywords_set").on('click', ".comment", function(event) {
    

    because in practice all other comments you have will be proccessing N times the click event that you are adding to be processed multiple times

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

Sidebar

Related Questions

$(document).ready(function() { $('#content').html(''); $.ajax({ url:'data.json', dataType: json, success: function(data) { $('#content').append('<p>'+data.rank+'</p>'); } });}); In
$(document).ready(function () { $('#keywordframe').contents().find(#step12).html(''); $('#keywordframe').contents().find(#step12).html('11'); $('#keywordframe').contents().find(#step13).html(''); $('#keywordframe').contents().find(#step13).html('12'); $('#keywordframe').contents().find(#step14).html(''); $('#keywordframe').contents().find(#step14).html('13'); $('#keywordframe').contents().find(#step15).html(''); $('#keywordframe').contents().find(#step15).html('14'); }); I try
$(document).ready(function(){$([href]).appendTo( Click here ...);}); HTML Code <a href=#> b </a> I want to to
$(document).ready(function() { $('form#search').bind(submit, function(e){ e.preventDefault(); $('#content').html(''); // Define the callback function function getGeo(jsonData) {
$(document).ready(function() { $.ajax({ type: 'post', async: false, url: 'WebService.asmx/GetCustomerInformation', data: '{}', contentType: 'application/json;charset=ytf-8', dataType:
$(document).ready(function(){ iframeSize() }); $(html).live(click, function( event ){ iframeSize() }); $(html).live(keypress, function( event ){ iframeSize();
jQuery(document).ready(function($){}); is a known and great way to protect the $ from causing errors.
jQuery(document).ready(function(){ var panelContainer = jQuery('div#panels'); jQuery('<div id=tabs></div>').insertBefore(panelContainer); panelContainer.find('div.panel').each(function(n){ jQuery('div#tabs').append('<a class=tab href=#' + (n+1) +
$(document).ready(function() { $('#comment textarea').click(function() { if (this.value == this.'Post a comment') { this.value =
$('document').ready(function() { $.getJSON('news.php', parseInfo); }); function parseInfo(data) { alert(data.news);//undefined $('#info').html(data.news); } My PHP output(news.php)

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.