1

I need to use jquery to add some elements on small screens and then remove them on larger screens. But for some reason, .remove() is not removing anything. All my other code is working - just not .remove(). What am I doing wrong?

jQuery(function ($) {
    var resizeflag = false;
    $(window).resize(function () {
        if ($("#wrapper").css("overflow") === "visible") { // sample css to test if media query has fired
            if (resizeflag == false) {
                resizeflag = true;
                // add mobile menu icon
                $('#mobile-menu').before('<a id="menu-icon">Menu</a>');
                // add Economic Development to header on homepage only
                $('#homepage #site-logo').after('<div class="logo-tag">ECONOMIC DEVELOPMENT</div>');
                // add footer logo 
                $('#footer-nav').prepend('<div class="mobile-footer-logo"></div>');
            }
        } else {
            if (resizeflag == true) {
                resizeflag = false;
                // must undo these DOM manipulations if the browser is expanded again or else it will loop 
                $("a#menu-icon").remove();
                $('div.logo-tag').remove();
                $('.mobile-footer-logo').remove();
            }
        }
    }).resize();
});
4

1 回答 1

0

我能够弄清楚。我的问题是我需要以相反的顺序删除元素。它实际上与 .remove() 函数没有任何关系——它是一些元素依赖于其他也被移动的元素(在我上面截断的代码中没有显示)。

希望这对可能处于这种非常特殊情况的其他人有所帮助。

于 2013-09-20T19:36:30.587 回答