I basically try to do exactly what the item offers, but I get "undefined" in my warning, and I'm not quite sure why. I'm new to jquery, so I probably have the wrong syntax, but not sure where to go from here. I will send both my attempts, which both give "undefined" in the message ...
//In my first attempt, I'm trying to get the id of the inner a tag <ul> <li id="l1" class="active"><a href="#c1">Samp 1</a></li> <li id="l2" class=""><a href="#c2">Samp 2</a></li> <li id="l3" class=""><a href="#c3">Samp 3</a></li> </ul> var selected = $(".active).children("a").attr("id"); alert(selected); //In my second attempt, I'm trying to get the id of the currently selected li var selected = $(".active").attr("id"); alert(selected);
jquery attributes element
pixie54
source share