Skip to content Skip to sidebar Skip to footer

How To Increment Div Id Value?

I have got a task to set the menu as selected. For that I use dynamic id. So I want to increment it with respect to the selection My code is

Solution 2:

This is the way to do it with Jquery

valelementList= $(".menu");
for (vari=1; i <= list.length; i++) {
    elementList[i].attr("id", "menu" + i);
}

Solution 3:

Just use a class name instead of an id, you will be able to reuse the code you have just added but in this way.

var list = $(".menu");

One advice, don't do the highlighting of the item menu with javascript, do it server-side, and you can add the "activating" class directly in the HTML of the LI.

Post a Comment for "How To Increment Div Id Value?"