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
<div class="menuHeader ui-corner-top" id="menu"+ i>
<span><a href="#" onclick="Home()">Home</a></span>
</div>
<div class="menuHeader ui-corner-top" id="menu"+ i>
<span><a href="#" onclick="NewTransaction()">New Transaction</a></span>
</div>
<div class="menuHeader ui-corner-top" id="menu"+ i>
<span><a href="#" onclick="Portfolio()">Portfolio</a></span>
</div>
javascript is
$(document).ready(function () {
alert(document.URL);
var list = $("#menu");
for (var i = 1; i <= list.length; i++) {
list[i].innerHTML = i;
}
var str = document.URL.toLowerCase().indexOf("portfolio/index");
alert(str);
if (str >= 0) {
$('#menu').addClass("menuHeaderActive");
}
});
How can I do this?
var i=0;
$('.menuHeader').each(function(){
i++;
var newID='menu'+i;
$(this).attr('id',newID);
$(this).val(i);
});
This is the way to do it with Jquery
val elementList = $(".menu");
for (var i = 1; i <= list.length; i++) {
elementList[i].attr("id", "menu" + i);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With