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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:04:39+00:00 2026-06-11T12:04:39+00:00

How to get the size of an HTML element in bytes using javascript? I

  • 0

How to get the size of an HTML element in bytes using javascript?

I have a list that represents a conversation

<ul>
  <li>hello</li>
  <li>how are you?</li>
  <li>fine thanks</li>
  <li>nice to meet you</li>
  <li>nice to mmet you too</li>
</ul>

And I want to save that conversation to localStorage, but localStorage limit is 5MB in chrome, so I need to know the size in bytes for the list to do some validations.

  • 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-11T12:04:40+00:00Added an answer on June 11, 2026 at 12:04 pm

    If you are trying to convert the element to HTML, then you could give the <ul> an ID then use

    var el = document.getElementById("convo");
    var html = el.innerHTML;
    window.alert(html.length);
    

    Or, if there will be a lot of markup and you want to just get the text, you could loop through the li elements and extract just the text and put that in an array. JSON.stringify the result and get its length.

    Edit:

    Javascript uses UCS-2 or UTF-16 internally, both of which are 16 bit encodings. Assuming Latin text, <string>.length *2 should be a fairly accurate estimate.

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

Sidebar

Related Questions

I have followed an online tut to get a full-size background using an inline
I have an html div that is of a fixed size and an additional
I have a HTML file that I want to read using Jsoup and export
I am trying to get the font size of selected range in a html
I need to get the size of a directory, recursively. I have to do
How can I get the size in bytes of the data returned from the
How to get file size of pdf,gif,doc etc using xcode. suppose to i get
How get HTML element from Google maps marker (v3)? <div style=overflow-x: hidden; overflow-y: hidden;
I have the following HTML: <h2>Embed Code</h2> <pre> <code> &lt;script type=&quot;text/javascript&quot;&gt; var something =
I have a simple html page with a div element in it. The innerHTML

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.