<body>
<div data-role="page">
<div align="center" id="mainPageContent1" data-role="content">
<div data-role="controlgroup" id="game_part1s" data-type="horizontal">
<a data-role='button' id='btn1' href='javascript:changeGamePart("Reset1");'>0 - 5 min</a>
<a data-role='button' id='btn2' href='javascript:changeGamePart("2");'>6 - 10 min</a>
<a data-role='button' id='btn3' href='javascript:changeGamePart("3");'>10 - 15 min</a>
<a data-role='button' id='btn4' href='javascript:changeGamePart("4");'>16 - 20 min</a>
</div>
</div>
</div><!-- /page -->
<script>
$(document).ready(function() {
setInitialGamePart();
});
function setInitialGamePart() {
changeGamePart(1);
}
function changeGamePart(nButtonId) {
for (var iPart = 1; iPart < 5; iPart++) {
if (nButtonId == iPart) {
//alert('add class' + iPart);
$('#btn' + iPart).addClass("ui-btn-active");
} else {
//alert('remove class' + iPart);
$('#btn' + iPart).removeClass("ui-btn-active");
}
}
}
</script>
</body>
On Page Init, the setInitialGamePart is called and it sets the first button as active and rest as not active. When I click any other button, all buttons go not active(normal buttons not highlighted)
Not sure what is the error here
JSFiddle here http://jsfiddle.net/fFZ6S/
As you will see, the init works fine but clicking on the button does not. help please
I fixed this by changing the href to href=’#’ so old code was
my new code looks like
Got the hint from this stack..
jquery mobile force ui-btn-active on navbar button
Here is the JSFiddle for you guys
http://jsfiddle.net/fzaqu/
Hope it helps you