1

I am attempting to get the list value through a jquery function attached to the css menu.

My code is as follows.

    $.fn.appmenu = function(options){

    //problem
    $(this).click(function(){
        alert($(this).filter("ul li").html());
    });

    $(this).hover(function(){
        $(this).filter("li").animate({
            top:"20px"
        });
    });

    //this.find('li:last').after("<li>test</li>");
    var lists = '<li title="Home" link="index.php"></li>';

    $.each(options, function(index, value) { 
        lists += '<li style="background-image:url(images/'+value[1]+'.png);" title="'+value[0]+'" link="'+value[1]+'"></li>';
    });

    return this.html("<ul>"+lists+"</ul>")
}

I call my menu using:

    //title, icon, link
$("#app-menu").appmenu([
    ["add", "address", "#link1"],
    ["contact", "comment", "#link2"],
    ["about", "pencil", "#link3"]
]);

Any help would be appriciated.

1
  • 1
    Can you add your markup as well? Commented Dec 21, 2011 at 12:49

2 Answers 2

1

Your html structure is not correct. The <li> tags are invalid and jQuery does not like your lists variable content.

I have altered your fiddle a little bit but it's now working. See http://jsfiddle.net/6yLYZ/.

Sign up to request clarification or add additional context in comments.

Comments

1

You must use find instead filter - filteris looking for elements from current set, find is looking of any elements from current set also through whole their children

However , the result will be the same because html function is get a whole html which is in first element from matches elements - in your example what is between <li> and </li>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.