skip to Main Content

Is there a way to link to another page without refreshing or reloading the page using JS. I’m having a hard time figuring it out

I need, I’m new in JS

Here is my Navbar Code

<div id="app">
        <nav id="nav">
            <div>
                <a class="nav-a on" onclick="home()" style="pointer-events: none; transform: translate3d(0%, 0%, 0px);"
                    href="/">HOME</a>
            </div>
            <div>
                <a class="nav-a" onclick="work()" style="transform: translate3d(0%, 0%, 0px); pointer-events: all;"
                    href="/work.html">WORK</a>
            </div>
            <div>
                <img class="logo" src="Other Files/SVG/LogoName(White).svg" alt="LOGO">
            </div>
            <div>
                <a class="nav-a" onclick="about()" style="transform: translate3d(0%, 0%, 0px); pointer-events: all;"
                    href="/about.html">ABOUT</a>
            </div>
            <div>
                <a class="nav-a" onclick="contact()" style="transform: translate3d(0%, 0%, 0px); pointer-events: all;"
                    href="/contact.html">CONTACT</a>
            </div>
        </nav>
</div>

2

Answers


  1. Look into the use of jQuery.load().

    This allows you to load HTML from a URL, and display it in an element in your page.

    Mock HTML:

    <div id="links">
        <a href="/contactus.html">Contact Us </a>
    </div>
    <div id="content"></div>
    

    JS:

    $(function() {
        $("#links > a").click(function(e) {
            e.preventDefault(); //so the browser doesn't follow the link
    
            $("#content").load(this.href, function() {
                //execute here after load completed
            });
        });
    });
    
    Login or Signup to reply.
  2. Have you tried turbo link??
    https://github.com/turbolinks/turbolinks
    Hope this will help

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search