javascript - How to know the exact children number of Ul element? -


i newbie in web development. not sure if dumb question.

<nav class="navigation">     <ul class="navigation-items-container">       <a href="#"><li class="navigation-items">home</li></a>       <a href="#"><li class="navigation-items">about</li></a>       <a href="#"><li class="navigation-items">blog</li></a>       <a href="#"><li class="navigation-items">contacts</li></a>     </ul> /nav> 

on hover of each li want know in children number of ul. i.e on hovering "home" should give children number 0 , on hovering "blog" should give children number 2.

as you've included jquery tag i'll post jquery based answer - if want non-jquery answer let me know:

$(".navigation-items-container li").hover(function(e) {     var index = $(this).index(); }); 

and fyi markup wrong, anchors should inside li tags

the version current code (though should changed):

$(".navigation-items-container a").hover(function(e) {     var index = $(this).index(); }); 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -