DIV clone from one page to another

Asked

Viewed 64 times

1

Hello I’m having trouble copying the side menu of the home page to the category page, I usually use the command below to copy div to the same page, but for different pages I’m not getting

<script type="text/javascript">
$(function(){
    $('.pagina-inicial .menu.lateral.fechado.borda-principal').clone().appendTo($('.pagina-categoria .coluna.span3.esquerda'));
});

do not know if I need to allocate the information elsewhere and then play on the page I want or make a direct copy

1 answer

1


You cannot do this with Javascript because it requires server-side handling. Javascript is only for the client, it will only work for the same page.

What you can do is in a standard js file that will be used on all pages, create the side menu in Javascript and include in an element that will exist on all pages.

I used jQuery. Just add the library to the head of your document.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>

The same can be done in pure Javascript, just call the function in window.onload.

Simply put, it would be something like this:

Html

<div id="areaDoMenu">

</div>

jQuery

$(document).ready(function() {
$("#areaDoMenu").append(
          '<ul>' +
            '<li>Item 1</li>' +
            '<li>Item 2</li>' +
            '<li>Item 3</li>' +
            '<li>Item 4</li>' +
            '<li>Item 5</li>' +
          '</ul>');
});

See here > http://jsfiddle.net/Lc0eprhs/

  • 1

    ah yes, I understood, it turns out that the site that I’m developing pertaining to a platform that already has a model, I’m just improving the layout, to get more attractive, and they have 2 side menu templates, which vary in the pages of the site, being one of these templates that I wanted to take, and leave only the template of the initial page for the other pages, well I thank the attention, I will analyze and see if I develop another menu and apply

Browser other questions tagged

You are not signed in. Login or sign up in order to post.