The reason it doesn’t work in jsfiddle is because your CSS doesn’t match the HTML -
<ul id="menu">
.ui-menu {}
For the menu itself, try removing float:left; and replacing with inline-block -
ul > li {
position: relative;
display: inline-block;
width: auto !important;
}
.ui-menu ul li ul li {
position: relative;
display: block;
width: auto !important;
}
You really don’t need to keep floating things left, I’m not really sure what you’re trying to achieve from it.
Side note: When you float an element, it automatically becomes display: block; … that means you don’t need to keep doing -
float: left;
display: block;
Simply do -
float: left;
> The reason it doesn’t work in jsfiddle is because your CSS doesn’t match the HTML
Why this works in jsfiddle? http://jsfiddle.net/8Observer8/7Bvap/227/
Because it’s different javascript that’s allocating the class to the menu. That method seems pointless when you could allocate the class via HTML.
Why do you write without “.ui-menu”?
ul > li {
position: relative;
display: inline-block;
width: auto !important;
}
Because .ui-menu wasn’t being used. I don’t understand what you’re trying to achieve using the javascript to assign the CSS style?