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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:30:12+00:00 2026-05-19T12:30:12+00:00

Take the following page: <html> <head> <script src=https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js type=text/javascript/> </head> <body> <div class=hashtag>#one</div> <div

  • 0

Take the following page:

<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"/>
</head>
<body>
    <div class="hashtag">#one</div>
    <div class="hashtag">#two</div>
    <form accept-charset="UTF-8" action="/home/index" method="post">
        <textarea id="text-box"/>
        <input type="submit" value ="ok" id="go" />
    </form>

    <script type="text/javascript">
        $(document).ready(function() {

            $(".hashtag").click(function() {
                var txt = $.trim($(this).text());
                $("#text-box").append(txt);
            });

        });
    </script>
</body>
</html>

The behavior I would expect, and that I want to achieve is that when I click on one of the divs with class hashtag their content (“#one” and “#two” respectively) would be appended at the end of the text in textarea text-box.

This does happen when I click on the hash tags just after the page loads. However when I then also start editing the text in text-box manually and then go back to clicking on any of the hashtags they don’t get appended on Firefox. On Chrome the most bizarre thing is happening – all the text I type manually gets replaced with the new hashtag and disappears.

I probably am doing something very wrong here, so I would appreciate if someone can point out my mistake here, and how to fix that.

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-05-19T12:30:12+00:00Added an answer on May 19, 2026 at 12:30 pm

    2 things.

    First, <textarea/> is not a valid tag. <textarea> tags must be fully closed with a full </textarea> closing tag.

    Second, $(textarea).append(txt) doesn’t work like you think. When a page is loaded the text nodes inside the textarea are set the value of that form field. After that, the text nodes and the value can be disconnected. As you type in the field, the value changes, but the text nodes inside it on the DOM do not. Then you change the text nodes with the append() and the browser erases the value because it knows the text nodes inside the tag have changed.

    So you want to set the value, you don’t want to append. Use jQuery’s val() method for this.

    $(document).ready(function(){
      $(".hashtag").click(function(){
        var txt = $.trim($(this).text());
        var box = $("#text-box");
        box.val(box.val() + txt);
      });
    });
    

    Working example:
    http://jsfiddle.net/Hhptn/

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

Sidebar

Related Questions

I have the following jQuery function embedded in an MVC Razor page: <script type=text/javascript>
Consider the following HTML: (Written for Google Chrome) <html> <head> <script language=javascript> function AddToIFrame(){
Take the following markup: <!DOCTYPE html> <html> <head> <title>My test for StackOverflow</title> </head> <body>
I am trying to display a page that uses jQuery. The AJAX functionality implemented
I've created the following JSP: <!-- WebContent/pages/ResourceBundlesJST.jsp --> <%@ page language=java contentType=text/html; charset=ISO-8859-1 pageEncoding=ISO-8859-1%>
Take the following snippet: List<int> distances = new List<int>(); Was the redundancy intended by
Take the following two lines of code: for (int i = 0; i <
Take the following string as an example: The quick brown fox Right now the
Take the following C# class: c1 { event EventHandler someEvent; } If there are
Take the following generics example import java.util.List; import java.util.ArrayList; public class GenericsTest { private

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.