How to maintain the modifications made with Jquery?

Asked

Viewed 32 times

-2

In an HTML page that is outside the index I need to insert my age inside an element.

The error happens when I click to be forwarded to another page, the text the script inserted disappears, how do I make the text never change?

I already put the script inside the.js script next to $(Document).ready..... and did not resovlveu.

if you prefer, take a look at the site to see the "error" happening: https://vitorcorrearosa.tech/

BELOW IS ALL THE CODE

    <div class="sobreArea">
    <img src="/images/vitor_correa.jpg" alt="Vitor Correa Rosa" class="vitorCorrea">
    <p class="profissao">Desenvolvedor Web - Front-End</p>
    <p class="textoSobre">
        Lorem ipsum, dolor sit amet <idade></idade> adipisicing elit. Exercitationem voluptatem architecto excepturi quibusdam repudiandae atque veritatis maxime tempora, hic aut? Deleniti a obcaecati, distinctio odit ducimus quisquam sapiente ad. Hic?
    </p>
    </p>
    <div class="redesSociais">
        <a href="https://github.com/vitorcorrearosa" target="_blank"><img src="/images/github.png" alt="github"></a>
        <a href="https://www.linkedin.com/in/vitorcorrearosa/" target="_blank"><img src="/images/linkedin.png" alt="linkedin"></a>
    </div>
</div>
<script>
let d = new Date();
    let year = d.getFullYear()
    let idade = year - 1997   

    $("idade").text(idade)
</script>

in index.html has a script that calls the pages . html when the user clicks the page reference button.

$(document).ready( function(){
    $("#main").load("paginas/home.html")

    // Menu em JS
    $("#projetosButtom").click(function(){
        $("#main").load("paginas/projetos.html")
    })
    $("#perfilButtom").click(function(){
        $("#main").load("paginas/perfil.html")
    })
    $("#homeButtom").click(function(){
        $("#main").load("paginas/home.html")
    })    
})

<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="css/style.css">
    <link rel="shortcut icon" href="images/letter-v.png" type="image/x-icon">        
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <title>Vitor Correa Rosa</title>
</head>
<body>
    <header>
        <section id="cabecalho">
            <h2>vitor correa rosa</h2>
            <nav id="menu">
                <ul>                            
                    <li id="homeButtom">inicio</li>
                    <li class="traco">-</li>
                    <li id="perfilButtom">perfil</li>
                    <li class="traco">-</li>
                    <li id="projetosButtom">projetos</li>
                </ul>
            </nav>
        </section>
    </header>
    <main id="main">
    </main>
    <script src="script.js"></script>
    
</body>
</html>

  • I entered the page and it is written Hello, World! My name is Vitor Correa, I am 24 years old! then the error did not occur in Chrome. In the first fragment there is a tag </p> and you also included a custom tag <idade> where you want to enter the value dynamically, it turns out that the process of inserting custom tags in the document is not a simple thing see in the link I passed that to use a custom tag you need to register in the DOM and if you do not register some browsers may ignore.

No answers

Browser other questions tagged

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