jquery adding greater than symbol for li which has submenu

17 Sep

I have done this for my need, you can use this code to modify to your need to insert icon or something like that in li which has another li inside it.

My html list structure

<ul class="menu">
<li>Home items
<li>Car Accessories
<li>Car Speakers
<li>Car Stereos
<li >Sony
<li>Car Subwoofers Amplifiers Tweeters
<li>Other Car Accessories

So, we have three level ul list.

Note here I’m interested in adding ‘>’ symbol for only second level ‘li’ elements which have a ‘ul’ element inside them.
use this jquery algo if your problem matches this logic

$(document).ready(function() {
//on dom ready
    $('ul.menu').children().each(function() {
//looping over children of first level ul
        $(this).children('ul').children().each(function() {
//looping over children of 2nd level ul
            $(this).children('ul').each(function() {
//check for ul child in li element and excecutes the function. each function is added just for the sake of implementing the following function
                $(this).before('<p class="lessthan">&gt;</p>');

Live example

Thanks for visiting

Update for this code

function getnavmenu($parent,$root){
	if($parent->count() > 0){
		echo "<li>".$parent->getname();
		echo "<ul>";
		foreach( $parent->children() AS $child ){
		echo "</ul>";
			echo "</li>";
		echo "<li>".$parent."</li>";
if (file_exists('blocks/blocknav/nav.xml')) {
    $nav = simplexml_load_file('blocks/blocknav/nav.xml');


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: