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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:04:27+00:00 2026-05-26T10:04:27+00:00

When I begin writing text in the textarea, I want the outer div, with

  • 0

When I begin writing text in the textarea, I want the outer div, with a class box, to have its border turned solid instead of dashed, but somehow the :focus doesn’t apply in this case. If it works with :active, how come it doesn’t work with :focus?

Any ideas why?

(Note. I want the DIV’s border to turn solid, NOT the textareas)

div.box
{
    width: 300px;
    height: 300px;
    border: thin dashed black;
}

div.box:focus{
    border: thin solid black;
}

<div class="box">
    <textarea rows="10" cols="25"></textarea>
</div>
  • 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-26T10:04:27+00:00Added an answer on May 26, 2026 at 10:04 am

    While this can’t be achieved with CSS/HTML alone, it can be achieved with JavaScript (without need of a library):

    var textareas = document.getElementsByTagName('textarea');
    
    for (i=0;i<textareas.length;i++){
        // you can omit the 'if' if you want to style the parent node regardless of its
        // element type
        if (textareas[i].parentNode.tagName.toString().toLowerCase() == 'div') {
            textareas[i].onfocus = function(){
                this.parentNode.style.borderStyle = 'solid';
            }
            textareas[i].onblur = function(){
                this.parentNode.style.borderStyle = 'dashed';
            }
        }
    }
    

    JS Fiddle demo.

    Incidentally, with a library, such as jQuery, the above could be condensed down to:

    $('textarea').focus(
        function(){
            $(this).parent('div').css('border-style','solid');
        }).blur(
        function(){
            $(this).parent('div').css('border-style','dashed');
        });
    

    JS Fiddle demo.

    References:

    • getElementsByTagName().
    • onfocus.
    • onblur.
    • parentNode.
    • tagName.
    • toString().
    • toLowerCase().
    • style.
    • focus().
    • blur().
    • parent().
    • css().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an add-in for PowerPoint, and want to get the text from the
I'm working on building the URLs for my REST API before I begin writing
I have a large SQLite database with a mix of text and lots of
I'm writing a program for some data entry I have to periodically do. I
I've learned enough to begin writing programs from scratch, but I'm running into the
I've been writing a c# program for the last couple weeks and the text
I've been considering writing my own UI framework. This is mostly because I have
I have an application that imports data read from text files from a directory
Let's say I'm writing text viewer for the iPhone using Core Text. Every time
I have two text files bala.txt and bala1.txt bala.txt contains text line by line

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.