jQuery before() method is breaking a generated sub menu when using jQuery 1.9.1, fine on previous version,
<p>I am building a select drop down menu for mobile devices based on a pre-existing UL, this was working fine with an old version of jQuery (1.4.1). However, I have updated jQuery to version 1.9.1 and the code now breaks the menu. The section which is breaking is actually the child menu of the section that you are currently viewing. </p>

<pre><code>var mobileMenu = function (menuParent, prevSibling) {

    var $select = $('&lt;select&gt;', {
        class: 'mobileMenu'
    }).insertAfter(prevSibling);

    $(menuParent).each(function () {
        var $li = $(this),
            $a = $li.find('&gt; a'),
            $p = $li.parents('li'),
            prefix = new Array($p.length + 1).join('-');

        var $option = $('&lt;option&gt;')
            .text(prefix + ' ' + $a.text())
            .val($a.attr('href'))

        if ($(this).hasClass("selected")) {
            $option.attr('selected', true);
        }

        $option.appendTo($select);

        if ($(this).hasClass("selected")) {
            mobileSubNav($select);
        }

    });

    $(".mobileMenu").change(function () {
        window.location = $(this).find("option:selected").val();
    });
};

var mobileSubNav = function (navContainerName) {
    $('.main_nav_sub li').each(function () {
        var $li = $(this),
        $a = $li.find('&gt; a'),
        $p = $li.parents('li'),
        prefix = new Array($p.length + 1).join('-');

        var $option = $('&lt;option&gt;')
        .text(prefix + '--' + $a.text())
        .val($a.attr('href'));
        $option.before(navContainerName);
    });
}
</code></pre>

<p>It appears to be the 3rd to last line - the before() method. I see on the upgrade guide for jQuery version 1.9 it states 'attempting to use .after(), .before(), or .replaceWith() on a node without a parent has no effect'. Does this mean my script is breaking becuase the parent element is not yet added to the dom? Could anyone shed any light on what is happening and point me in the firrection to fix it?</p>

<p>Thanks</p>
