---
title: "Printing element width in javascript"  
description: "Printing element width in javascript"  
author: "Anonymous User"  
published: 2013-10-07  
updated: 2013-10-08  
canonical: https://www.mindstick.com/forum/1648/printing-element-width-in-javascript  
category: "javascript"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# Printing element width in javascript

I'm [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to [retrieve](https://www.mindstick.com/forum/34400/how-to-retrieve-form-values-in-controller-action) an [html](https://www.mindstick.com/articles/1530/design-a-simple-stylish-calculator-using-html-css-and-javascript) element width in [javascript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript). Nothing appears on [screen](https://www.mindstick.com/forum/33644/loading-screen-during-ajax-call)

```
<head>
<script type="text/javascript">
    var width = $("#menu").width();
    document.write(width);
</script>
</head>
<body>
    <h1> Example </h1>
<ul id = "menu">
    <li><img src="img/Logo.jpg"/></li>
    <li><a href ="#">Home</a>
        <ul class = "sub1">
            <li><a href ="#">News</a></li>
        </ul>
    </li>
    <li><a href ="#">Machines</a>
        <ul class = "sub1">
            <li><a href ="#">Type1</a></li>
            <li><a href ="#">Type2</a></li>
            <li><a href ="#">Type3</a></li>
        </ul>
    </li>
    <li><a href ="#">Mission</a></li>
    <li><a href ="#">Contacts</a></li>
</ul>
<div id "main">
    <h2> Whatever </h2>
</div>
</body>
```

\

\

## Replies

### Reply by Anonymous User

```
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script><div id=head></div><script type="text/javascript">     $(function(){ // called when the DOM is ready          var width = $("#menu").width();          $('#head').html(width);     });</script>
```


---

Original Source: https://www.mindstick.com/forum/1648/printing-element-width-in-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
