I am trying to get links from the menu and display them in a block with the html-map class, but the links are not displayed, how can I fix it?

$(document).ready(function(){ var html_link = []; if(location.pathname == '/html-karta'){ $.each($("ul.menu-main a"), function(i,e) { html_link.push($(e).attr('href')); $.each(html_link, function(i,e){ $('.html-map').html($(e)); }) }) } }) 

    1 answer 1

    Did not quite understand the train of thought in your code)

    Working solution

     $(document).ready(function() { if (location.pathname == '/html-karta'){ $.each($("ul.menu-main a"), function() { $('.html-map').append($(this).html()); }); } }); 
    • But do not tell me how to add the href to the link? Just such a construction does not work $('.html-map').append('<a>'+$(this).attr('href').html()+'</a><br>'); - ChromeChrome
    • one
      $ ('. html-map'). append ('<a href="' + $(this).attr('href') +'"> Link text </ a‌> <br>') - Kison
    • one
      Or so var htmlMap = $ ('. Html-map'); $ ('a', {'href': $ (this) .attr ('href')}). appendTo (htmlMap); - Kison
    • If the nested menu is possible in any way, get links and display them with such nesting as in the menu? - ChromeChrome
    • IMHO, create another question. In it, formulate the problem that you have. Just do not forget to add code with which problems. - Kison