I have some jquery which will calculate the items in my menu and assign the li with a calculated width in px.
here is the code:
$(document).ready(function(){
$('div#new-menu-lower ul li').css('width', ($('div#new-menu-lower ul').width() / $('div#new-menu-lower ul li').length));
$(function() {
var menuWidth = $('div#new-menu-lower ul').width();
var listItems = $('div#new-menu-lower ul li').length;
var itemWidth = Math.floor(menuWidth * (1/listItems)) - 40;
$('div#new-menu-lower ul li').css('width', itemWidth);
});
});
The problem is listItems shows up as 38 items and it seems to calculate every single li which is wrong. It should just count the first ul li’s NOT the child elements.
Is there anything i can do to stop this happening?
Change
to
You need jQery parent > child selector to achieve your job.
From jQuery doc: