I want click on next li item from current active item. Which li is active, its a tag contain active class.
So first of all, I get active a tag and it’s parent li. Now I get index of li in ul . Then add 1 in its value and get next a tag and fire click event on it.
My code is working fine in IE and Firefox, but in Chrome I get following exception.
“Uncaught TypeError: Object #<an Object> has no method ‘click'”
please suggests me usable link or sample code or correction in my code.
My html code is :-
<nav class="cycle-nav-container" role="navigation">
<ul class="list-b" id="cycle-1-nav">
<li class="hitmo"><a href="http://hitmo-studio.com/#hitmo">Hitmo</a></li>
<li class="fastpr"><a href="#" class="active">FastPr</a></li>
<li class="thinkmedia"><a href="http://hitmo-studio.com/#thinkmedia">Thinkmedia</a></li>
<li class="arkana"><a href="http://hitmo-studio.com/#arkana">Arkana</a></li>
<li class="bioway"><a href="http://hitmo-studio.com/#bioway">Bioway</a></li>
<li class="nana"><a href="http://hitmo-studio.com/#nana">Nanaform</a></li>
<li class="akademia"><a href="http://hitmo-studio.com/#akademia">Social Media Academy</a></li>
</ul>
</nav>
My Javascript code is:-
var navIndex = $('.cycle-nav-container .list-b .active').parent();
var nextIndex = $("ul.list-b li").index(navIndex) + 1;
var par = $("ul.list-b");
if(nextIndex>=par[0].children.length)
nextIndex=0;
var nextElement = par[0].children[nextIndex];
var navIndex12 = nextElement.children[0];
navIndex12.click();
To invoke the click handler for a DOM element, IE defines a click method which basically fires the click event . Firefox implemented it from FF 5+.
However Chrome still uses the standard W3C defined dispatchEvent for programatically firing the event.
Or it could also be that the navindex12 object returned could be a DOMTextElement. Try alerting the navindex12.nodeType
To conclude , you should try to gracefully check for browser and element constraints before calling the click method.