views:

25

answers:

1
function rotateimg(ulid,showid,linkid) { 
        var cur = $("#"+ulid+" li.current");            
        var nxt = cur.next("li");           

        if (nxt.length == 0)
        {
        nxt = $("#"+ulid+" li:first");
        }
        cur.removeClass("current"); 
        nxt.addClass("current");
        var img_value=nxt.attr("id").substring(11);
        var img_title=nxt.attr("title");
        var img_id = nxt.attr("name").substring(17);
        var alink=nxt.attr("rel");
        $("#"+linkid).attr("href",alink);

        $("#"+ulid+" li div").css("background-color", "#000000");
        nxt.find("div").css("background-color", "#333333");
        setimg(img_value,showid,img_title);

    }

var lt=setInterval("rotateimg('lnews','show_images_event','lnewslink')", 5000);

in this code. i am getting this error nxt.attr("id") is undefined

pls any one help me

+1  A: 

You'll get undefined if nxt has no id.
This is a problem, because you're trying to call .substring(11) on it.
Do a null check:

var img_value = "";
var nxtId = nxt.attr("id");
if(nxtId)
    img_value = nxtId.substring(11);
Kobi
thanks for reply.now the error not show but it not worked in chrome browser
shanmugam