Replace DIV if using mobile device

I have been searching but can’t find any info… I DON’T want to redirect users to a seperate mobile page, I only want a single div to be replaced if the user is on a mobile device.

Right now I’m just setting the code below on page load. But I need it to be an if statement that if mobile is true then either .replaceWith or set display settings for each div…



   jQuery('#swapcontentdesktop').replaceWith(jQuery('#swapcontentmobile'));

   $('#swapcontentdesktop').css({ 'display': 'block'});
   $('#swapcontentmobile').css({ 'display': 'none'});


Please help :hangover: