Search code examples
javascripthtmlanchor

Return2top anchor: How to use Javascript to place specific anchor in HTML?


I am starting a small webshop and do not have access to the HTML files. I can 'inject' CSS and Javascript though. I basically want to place the Return2top anchor below into the HTML files by 'injecting' Javascript:

<p><a href="javascript:" id="return-to-top"><i class="fa fa-chevron-up"></i></a></p>

Is this possible?


Solution

  • this is the javascript you'll need, not sure how exactly you plan on 'injecting' it though

    let btn = document.getElementById('return-to-top');
    btn.addEventListener('click', function (){
        window.scroll(0, 0);
    })