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

  • Home
  • SEARCH
  • 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 6943869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:12:44+00:00 2026-05-27T13:12:44+00:00

The basics: I’m styling a textarea with CSS, and using javascript to highlight the

  • 0

The basics:

I’m styling a textarea with CSS, and using javascript to highlight the textarea when the user clicks inside.

This works fine with one textarea, but when I try to make more (by changing the javascript from .getElementById to .getElementsByClassName and updating the tags accordingly) I mess something up and lose all of the CSS.

How can I make this work with two textareas?

Cheers and thanks for your help!

.html page:

<textarea name="styled-textarea" id="styled" ; this.onfocus=null; setbg('#e5fff3')">All      this nice stuff goes inside here | http://www.website.com</textarea>

<script type="text/javascript">
    var textBox = document.getElementById("styled");
    textBox.onfocus = function() {
    textBox.select();

    // Work around Chrome's little problem
    textBox.onmouseup = function() {
        // Prevent further mouseup intervention
        textBox.onmouseup = null;
        return false;
    };
};
</script>

All this nice stuff goes inside here.
<textarea name="styled-textarea" id="styled" ; this.onfocus=null; setbg('#e5fff3')">All     this nice stuff goes inside here | http://www.website.com</textarea>

CSS:

textarea#styled {
width: 60%;
font-size: 24px;
border: 3px solid #cccccc;
padding: 5px;
font-family:'Arial', sans-serif
}       
  • 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-27T13:12:45+00:00Added an answer on May 27, 2026 at 1:12 pm

    I tried to edit mrtsherman’s answer, but my suggestion was rejected, so I’ll just add a new answer. The code below fixes his.

    Switching from .getElementById to .getElementsByClassName requires three things:

    1. Changing id to class on both your textarea elements.
    2. Updating your CSS from textarea#styled to textarea.styled.
    3. Use .getElementsByClassName instead of .getElementById (note, it returns an array of elements, not one).

    Demo: http://jsfiddle.net/ThinkingStiff/WnJar/

    Script:

    var textBoxes = document.getElementsByClassName("styled");
    
    for (var i = 0; i < textBoxes.length; i++) {
    
        var textBox = textBoxes[i];
    
        textBox.onfocus = function() {
    
            this.select();
    
            // Work around Chrome's little problem
            this.onmouseup = function() {
    
                // Prevent further mouseup intervention
                this.onmouseup = null;
                return false;
    
            };
    
        };
    
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand the basics of inheritance but this one is confusing me. How would
So I have the basics setup already. This is my User model: # ==
Back to the basics... For reference types, one can do this: SomeType someObject =
To learn the basics of OCaml, I'm solving one of the easy facebook engineering
I know the basics of this methods,procedures,function and classes but i always confuse to
The basics of this query have been asked, and answered, many times before, but
I am trying the basics of setting up XMPP communication between android phones using
I know the very basics about using coroutines as a base and implementing a
I am trying to learn the basics of dependency injection (DI). To this end
I'm learning basics of JS and I wrote this script but it doesn't work

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.