Grab a link id and create div on another page

Asked

Viewed 98 times

1

Well, I’m trying to get id of a link that looks something like this

home php.

<ul class="nav">
   <li><a href="#" id="o-v">Teste</a></li>
</ul>


$(document).ready(function() {
    const o_v = document.getElementById('o-v');
        o_v.addEventListener('click', function(e) {
        var video = document.createElement('div');
        video.className="video";
        video.appendChild();
        console.log(video);
        // alert(o_v, video);
    });
});

so far so good, what I needed was to throw this div into my .box only that this .box is the noticia.php, it would be something like this, as I recover the class video being that she’s on another page?

php news.

$(document).ready(function() {
    const box = document.getElementByClassName('box');
    video.className="video";
    video.appendChild(box);
    console.log(video);
});

1 answer

1


First - your code is very messy, it’s mixing jQuery with Javascript, but, we can create the div video in that way:

$(function() {
  const o_v = $('#o-v');
  
  o_v.on('click', function() {
    var video = document.createElement('div');
    video.className = "video";
    video.id = "video";
    console.log(video);
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<ul class="nav">
  <li><a href="#" id="o-v">Teste</a></li>
</ul>

Now to retrieve the div video on the page php news., there are several forms, one of them is with the method load() jQuery, which is basically an Ajax method:

$(function() {
  $('.box').load('home.php #video');
})

This way you only bring the div video on the news page.php.

Browser other questions tagged

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