jquery - Uncaught TypeError: Cannot set property 'Width' of undefined -


i'm having issue dynamically setting width of ul element in website.

below jquery i'm uusing

var button = $("#navbar"); alert(button); var count = $("#header li").length; alert(count); $("#navbar").style.width = count * 110 

here's html

<div id="header" class="clearfix">     <div class="clearfix hidden">         <img src="/content/images/main-logo.png">     </div>     <div id="navbar">         <ul>             <li id="home">                 home             </li>             <li id="portfolio">                 portfolio             </li>             <li id="about">                             </li>         </ul>     </div> </div> 

the "alert(button)" returns [object object] it's not null (at least understanding of it) error mentioned in title whenever try set width of it.

anyone know i'm doing wrong?

you must use 1 of following code

$("#navbar")[0].style.width = count * 110 

or

$("#navbar").width(count * 110) 

because style property of dom element while $("#navbar") jquery object, not contain style property default.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -