bekommen eine id des untergeordneten Elements und speichern Sie in einer Variablen mit Hilfe von jquery?

Ich bin im Grunde versucht, genau das zu tun, was das Thema schon sagt, aber ich bin immer "undefined" in meinem alert, und ich bin mir nicht ganz sicher, warum. Ich bin ziemlich neu in jquery, so, wahrscheinlich habe ich die syntax falsch, aber nicht wissen, wohin Sie gehen von hier aus. Ich poste meine beiden versuche, die sowohl der Ertrag "undefined" im alert -...

//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);
InformationsquelleAutor pixie54 | 2010-05-25
Schreibe einen Kommentar