9

This is my jQuery part that makes my menu for my pages.

function fetchmenus() {
    $.getJSON('sys/classes/fetch.php?proccess=1', function(status) {
        // get line status
        $.each(status, function(i, item) {
            if (item.id == "1") {
                active = "class='active'";
                lastpageid = item.href;
            }
            else {
                active = "class='nonactive'";
            }
            $('<li id="' + item.href + '" ' + active + '><a href="#' + item.href + '">' + item.menuTitle + '<span class="menuspan" id="' + item.href + '"></span></a></li>').appendTo('#menuarea ul#mainmenu');

        });
    });
}

What I want to do is get the item.menuTitle in the <a but before the <span>.

Currently I do it on this way:

$('ul#mainmenu li').live('click', function(event) {
    //alert(this.id);
    $("li#" + lastpageid).removeClass();
    fetchpage(this.id);

    $("#largemenutop").html($(this).text());

    $("li#" + this.id).addClass("active");
    lastpageid = this.id;
});;

Is there a better way to do this?

peterh
  • 11,875
  • 18
  • 85
  • 108
RussellHarrower
  • 6,470
  • 21
  • 102
  • 204
  • its not clear to me what you are asking. are you looking for a better way to build up the html for the menu? Or to access the title of the anchor once the menu is built already? – Jeff May 06 '11 at 15:02
  • here is a sample
  • Messages4
  • What is happening it when I click that link it shows the following Messages4 when I want it to show Messages – RussellHarrower May 06 '11 at 15:34
  • Possible duplicate of [Using .text() to retrieve only text not nested in child tags](http://stackoverflow.com/questions/3442394/using-text-to-retrieve-only-text-not-nested-in-child-tags) – Stephan Weinhold Dec 26 '16 at 09:19