Home > DeveloperSection > Forums > Printing element width in javascript
Tanuj Kumar

Total Post:134

Posted on    October-07-2013 8:54 AM

 JavaScript JavaScript 

 1 Reply(s)
 1380  View(s)
Rate this:

I'm trying to retrieve an html element width in javascript. Nothing appears on screen

<script type="text/javascript">
    var width = $("#menu").width();
    <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>
    <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>
    <li><a href ="#">Mission</a></li>
    <li><a href ="#">Contacts</a></li>
<div id "main">
    <h2> Whatever </h2>

Pravesh Singh
Pravesh Singh

Total Post:101

Posted on    October-08-2013 1:12 AM

<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();

Don't want to miss updates? Please click the below button!

Follow MindStick