Skip to content

Instantly share code, notes, and snippets.

@Archie22is
Created June 19, 2019 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Archie22is/47edc3ee09dffc5a563aac2750018e8c to your computer and use it in GitHub Desktop.
Save Archie22is/47edc3ee09dffc5a563aac2750018e8c to your computer and use it in GitHub Desktop.
Append HTML list items to another list using jQuery
var $window = $(window);
function checkWidth() {
// get window size
var windowsize = $window.width();
// Move top menu items into parent menu
if (windowsize <= 991) {
if( $('.parent-menu ul').has('li.from-top-nav').length == 0) {
var top_nav = $('.top-menu ul li').clone();
var count = top_nav.lenth;
top_nav.each(function(i) {
var new_top_nav = $(this).addClass("from-top-nav");
var main_nav = $('.parent-menu ul');
});
top_nav.appendTo('.parent-menu ul');
}
$('span.search-text').remove();
} else if (windowsize => 992) {
// Destroy from-top-nav items and reverse the process
$('.parent-menu ul li.from-top-nav').remove();
// Append "search" text to search icon on mobile
var search_text = $( "<span class='search-text' style='font-weight:500;'>Search</span>" );
// only append if it doesn't exist
if ( $('span.search-text').length === 0 ) {
$('.search-icon').append(search_text).css('font-weight', '500');
}
}
}
// Execute on load
checkWidth();
// Bind event listener
$(window).resize(checkWidth);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment