jquery - How to choose array [0] and make it a link using javascript -
i have array, go different url when <a href="javascript:void(0)">hotel selection</a>
clicked. here have far. help.
<div id="menu"> <ul> <li class="left-edges inactive"></li> <li class="inactive" style="width: 149px;"> <a href="javascript:void(0)">hotel selection</a> </li> <li class="seperator"></li> <li class="inactive" style="width: 124px;"></li> <li class="seperator"></li> <li class="inactive" style="width: 170px;"></li> <li class="seperator"></li> <li class="active" style="width: 134px;"></li> <li class="seperator"></li> <li class="inactive" style="width: 71px;"></li> <li class="seperator"></li> <li class="inactive" style="width: 95px;"></li> <li class="right-edges inactive"></li> </ul> </div>
javascript
$ (document).ready(function () { $('#menu').click(function(){ var x = document.getelementbyid("menu").selectedindex; var y = document.getelementbyid("menu").options; if (y[x].index == "0") { window.location.href='https://google.com'; } }); });
both of following statements incorrect, return undefined.
var x = document.getelementbyid("menu").selectedindex; var y = document.getelementbyid("menu").options;
try following. set event listener on hyperlink, redirect when whatever conditions satisfied.
$ (document).ready(function () { $('#menu li a').click(function(){ var href =$(this).attr('href'); if (href.indexof('javascript')>=0) { alert('https://google.com'); //window.location.href='https://google.com'; } }); });
Comments
Post a Comment