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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:18:09+00:00 2026-06-02T16:18:09+00:00

I am writing a validator for visual correctness of html files. The goal is

  • 0

I am writing a validator for “visual correctness” of html files. The goal is to detect too wide elements.

Here is a demo of my problem.

The dotted red line is an indicator of the max width of the document (200px in this example). The first paragraph is fine, but the second is too wide. Nevertheless, all of the following commands still return “200px” as the width:

// all return 200, but the value should be larger   
$('#two').width();
$('#two').outerWidth();
$('#two').prop('clientWidth');

Please see the Fiddle for more details.

How can i detect such oversized elements?

Updated question: Better to ask, how can i detect text that exceeds the borders of their parent elements?

Updated requirement: I am not allowed to change anything in the source HTML or CSS. But i can do anything i want with jQuery to modify the document, so that i can detect those too wide elements.

  • 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-06-02T16:18:12+00:00Added an answer on June 2, 2026 at 4:18 pm

    As others have said, temporarily wrap the text node in an inline element.

    var two = document.getElementById('two'),
        text = two.firstChild,
        wrapper = document.createElement('span');
    
    // wrap it up
    wrapper.appendChild(text);
    two.appendChild(wrapper);
    
    // better than bad, it's good.
    console.log(wrapper.offsetWidth);
    
    // put it back the way it was.
    two.removeChild(wrapper);
    two.appendChild(text);
    

    http://jsfiddle.net/vv68y/12/

    Here is a getInnerWidth function that should be useful to you. Pass it an element and it will handle the wrapping and unwrapping.

    function getInnerWidth(element) {
    
        var wrapper = document.createElement('span'),
            result;
    
        while (element.firstChild) {
            wrapper.appendChild(element.firstChild);
        }
    
        element.appendChild(wrapper);
    
        result = wrapper.offsetWidth;
    
        element.removeChild(wrapper);
    
        while (wrapper.firstChild) {
            element.appendChild(wrapper.firstChild);
        }
    
        return result;
    
    }
    

    http://jsfiddle.net/vv68y/13/

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

Sidebar

Related Questions

I'm writing a C# DKIM validator and have come across a problem that I
I'm writing a web app that inserts and modifies HTML elements via AJAX using
I have a strange problem with the validation I am writing on a form.
Writing documentation in html requires some code examples. What to do with characters that
I'll be writing a validator for a specific file format (the format itself is
I'm writing a custom validator that is going to check for the existence of
So, I'm writing a custom validator to validate the Ajax Toolkit's Rating control. The
Writing a custom validator for a dropdownlist that is using autopostback. Seems to ignore
I am writing a custom validation set that will display all missing elements on
Hi I'm having some problem with a PHP page: I'm writing a little CMS

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.