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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:40:10+00:00 2026-05-29T12:40:10+00:00

For example, I have a contentEditable div and I can type in it. When

  • 0

For example, I have a contentEditable div and I can type in it. When the text reaches the bottom of the div, the browser automatically scrolls the div so that the end of the text and the cursor are still visible.

How do I prevent the div from scrolling so that the inputted text goes past the bottom of the div and so that you can no longer see the cursor while you type?

The behavior I’m trying to achieve is like in Photoshop: when you make a text box, and type too much, the cursor continues past the bottom of the box and you can’t see what you are typing. If you expand the box, you’ll see all the hidden text.

EDIT 2/7/2012 9:27am: This is what I have right now, but it looks glitchy because the scroll position is adjusted AFTER the keyup event: http://jsfiddle.net/trusktr/hgkak/6/ So before the keyup event, the cursor gets temporarily placed into view (for each keystroke). I’d like there to be no jumping, and for the cursor to remain below the end of the green div when there is excess text without the view jumping around (the jumping seems like an amateur hack on my part :D)

  • 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-29T12:40:14+00:00Added an answer on May 29, 2026 at 12:40 pm

    Let’s try a hack:

    • first we try to prevent or revert any scrolling
    • whenever the user presses a key we turn the element’s overflow property to visible to avoid scrolling of the content, but hide the element at the same time by setting its opacity to 0. Immediately afterwards we switch overflow back to hidden and show the element again.
    • to avoid flickering we create a clone of the editable element (with overflow: hidden) and show this element while the original one is hidden.

    Here we go (uses jQuery for DOM convenience):

    $(function() {
    
        var editableElement = $('#editable'), clonedElement;
    
        // Revert any scrolling                    
        editableElement.on("scroll", function(event) {
            editableElement.scrollTop(0);
    
            // Try to prevent scrolling completely (doesn't seem to work)
            event.preventDefault();
            return false;
        });
    
        // Switch overflow visibility on and off again on each keystroke.
        // To avoid flickering, a cloned element is positioned below the input area
        // and switched on while we hide the overflowing element.
        editableElement.on("keydown", function() {
    
            // Create a cloned input element below the original one
            if (!clonedElement) {
                var zIndex = editableElement.css('zIndex');
                if (isNaN(parseInt(zIndex, 10))) {
                    zIndex = 10;
                    editableElement.css({zIndex: zIndex});
                }    
    
                clonedElement = editableElement.clone();
                clonedElement.css({
                    zIndex: zIndex-1,
                    position: 'absolute',
                    top: editableElement.offset().top,
                    left: editableElement.offset().left,
                    overflow: 'hidden',
                    // Set pseudo focus highlighting for webkit
                    // (needs to be adapted for other browsers)
                    outline: 'auto 5px -webkit-focus-ring-color'
                });
                editableElement.before(clonedElement);
            } else {
                // Update contents of the cloned element from the original one
                clonedElement.html(editableElement.html());
            }
    
            // Here comes the hack:
            //   - set overflow visible but hide element via opactity.
            //   - show cloned element in the meantime
            clonedElement.css({opacity: 1});
            editableElement.css({overflow: 'visible', opacity: 0});
    
            // Immediately turn of overflow and show element again.
            setTimeout(function() {
                editableElement.css({overflow: 'hidden', opacity: 1});
                clonedElement.css({opacity: 0});
            }, 10);
    
        });
    });
    

    Check this jsFiddle to play with the above code.

    Note that this may not be a complete solution (I have only tried it with Safari, Chrome and Firefox yet), but for the tested browsers it seems to work. You may want to fine-tune and polish your implementation (e.g. focus highlighting). In the jsFiddle example I have also turned off spell checking to avoid flickering markings.

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

Sidebar

Related Questions

I have a contentEditable div with following text for example: <div contentEditable='true'> This document
I have a contenteditable div that I want users to be able to select
Can i apply css to selected text in a contenteditable div instead of using
I have a <div> that has contentEditable=true . When I copy-paste content within the
If I for example have <p> some long text </p> on my HTML page,
Example: I have an class that inherits from UIImageView. An object creates an instance
I am using contentEditable div tags on my website and I have noticed a
For example have a source string: __aaXXccYYeeXX_ZZkkYYmmXX_ZZnnXXooYYuuXX_ZZvv.. How can I find all: aaXX*YY*ZZ __
is there a way to for example have checkboxes that store their variable to
I have a contentEditable DIV (building a kind of editor component). I am looking

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.