سؤال

I'm making a responsive navigation that moves part of a navigation in a different spot between mobile and desktop.

I'm using enquire.js for this to register my breakpoints and move things based on page width.

I am cloning the element and appending it to a different part of the page.

The issue i'm having is that when I go between the mobile and desktop views, the element gets cloned each time - so they start to pile up in desktop view.

I'm not that familiar with enquire.js to make it so that the element only clones if it doesn't already exist.

هل كانت مفيدة؟

المحلول

You can check the element length before cloning like,

if( !$('your-element').length ) // if element not exists then clone
{
    // your code to clone the element
}

If you provide some code to test or make a fiddle then it will more clear to us what you tried and what you need.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top