Saturday, November 19, 2011

Get the file name and change the active menu item css settings using J query


Here i have sample menu list.Now i want change the color of active item in menu comparing the file name for the which page is loaded at that time.Based on these information i can change the active link item settings.This all  happen when the page is loading
$(document).ready(function () {
    // $(function () {
    var urlFile = $.trim($.url.attr("file").replace(/([^.]*)\.(.*)/, "$1"));
    $('.Mainul li a').each(function () {
        var arrPath = $(this).attr('href').replace(/([^.]*)\.(.*)/, "$1").split('/');
        anchorFile = $.trim(arrPath[arrPath.length - 1]);
        //alert(urlFile + " == " + anchorFile);
        //alert(urlFile.length + " == " + anchorFile.length);
        if (urlFile == anchorFile) {
            $(this).css('color', 'Orange');
            divId = $(this).attr('id');
            $('#toggleText_' + divId).show();
        } else {
            $(this).css('color', 'green');
        }
    });

No comments:

Bel