jQuery.each – Getting li elements inside an ul

// note this array has outer scope
var phrases = [];

        // this is inner scope, in reference to the .phrase element
        var phrase = '';
            // cache jquery var
            var current = $(this);
            // check if our current li has children (sub elements)
            // if it does, skip it
            // ps, you can work with this by seeing if the first child
            // is a UL with blank inside and odd your custom BLANK text
            if(current.children().size() > 0) {return true;}
            // add current text to our current phrase
            phrase += current.text();
        // now that our current phrase is completely build we add it to our outer array
    // note the comma in the alert shows separate phrases

Recent Article

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Keep your skills sharp, get informed.

    Subscribe to our mailing list and get interesting stuff and updates to your email inbox