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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:53:32+00:00 2026-05-28T22:53:32+00:00

hey guys I have the follow code in js: $(document).ready(function(){ $(.replyLink).click(function(){ $(#form-to-+this.id).html(htmlForm()).toggle(500); return false;

  • 0

hey guys I have the follow code in js:

$(document).ready(function(){
$(".replyLink").click(function(){
    $("#form-to-"+this.id).html(htmlForm()).toggle(500);
return false;
});
function htmlForm(){
    var html;
    html ='<form class="comment-form" id="form-post" action="request.php" method="post">';
    html +='<input type="hidden" name="post_id" value="" />';
    html +='<input type="hidden" name="reply" value="" />';
    html +='<table><tr><td>Name:</td><td>';
    html +='<input class="name" type="text" name="name" size="20" maxlength="30"/>';
    html += ......
return html;
}

//this is not working!//////////////////////////////////////////
$(".comment-form input,.comment-form textarea").focus(function(){
    $(this).css({
        'background-color': 'white',
        'border':'1px solid #3faefc',
        'box-shadow': '0px 0px 2px 1px #95d3ff'
    });
});
/////////////////////////////////////////////////////////////
});

HTML i have link for e.x:

<a href='#' class="replyLink">Reply</a>

and when I click this a form toggle “somewhere” but i can not have control the element on the htmlForm() with about code!
Tnx

  • 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-05-28T22:53:32+00:00Added an answer on May 28, 2026 at 10:53 pm

    You can’t bind event handlers directly on elements that don’t (yet) exist. Probably the simplest change to fix this is to create all the forms up front in your document ready handler rather than creating them one at a time in the “.replyLink” click handler. Note that currently every time your click handler is called it recreates the form by setting the parent “#form-to-…” element’s html, regardless of whether it already existed.

    $(document).ready(function(){
       // create the forms up front
       $('[id^="form-to-"]').html(htmlForm());
    
       $(".replyLink").click(function(){
           $("#form-to-"+this.id).toggle(500); // don't set html here, just toggle
           return false;
       });
    
       function htmlForm(){
        /* your existing function body here */
       }
    
       $(".comment-form input,.comment-form textarea").focus(function(){
          /* your existing CSS setting code here */
       });
    });
    

    If for some reason that doesn’t fit with how you want to do things I can think of three other ways to get around this problem:

    1. Bind the focus event within your “.replyLink” click handler, after it creates the form elements.

    2. Use delegated event handling, i.e., use .delegate() or .on() (or .live() if you have a really old version of jQuery) instead of .focus() to attach the event handler to a parent element that does exist. This will then automatically apply to elements added later.

    3. Don’t create the form element dynamically. Have the form in your initial html markup and .hide() or .show() it when required.

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

Sidebar

Related Questions

Hey guys have her an code where i add an option to a html
Hey guys I have an ajax jquery function that receives data from a php
Hey guys I have a system where there is one form for each friend
Hey guys, I have a problem (again). This time I am trying to use
Hey guys! I have this little problem: I have one ViewController which adds 2
Hey guys, I have a problem with a code that I've been writing. I
Hey guys I have an array like this print_r($grouparray); Array ( [0] => Array
Hey guys I need some help with this: I have two view controllers, let's
hey guys i have got this far with a chat system but now i
Hey Guys I have the following simple Code : WhereAmIViewController.h #import <UIKit/UIKit.h> #import <CoreLocation/CoreLocation.h>

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.