mardi 19 mars 2019

How to search for by id for condition in Javascript, and then output text in another ?

Sorry, I tried to search for an answer, but I couldn't find exactly what I was looking for.

I am trying to make and webpage using Javascript, and I need some sort of decoder. For example, I have one abbreviation which is "NN", which stands for "Noun Nominative". Another abbreviation is "NA" which stands for "Noun Accusative". Another is "AN" which is "Adjective Nominative". There are many (too many) mixed-and-matched instances of these abbreviations, so I am trying to make a easy way for my Javascript/HTML code to search the whole page for every instance of "N" when it is the part of speech, and then output "Noun" in a different

when the abbreviation containing "N" is clicked. I hope this makes sense. So I came up with this:

    <html>

    <head>
    <script>
    function parseWord() {
        if (p.id === 'noun') {
            document.getElementById("part-of-speech-decoded").innerHTML = "Noun";
        }
    }
    </script>
    </head>

    <body>
    <div class="abbreviation" onclick="decodeWord()">
    <p id="noun">N</p>
    <p id="nominative">N</p>
    </div>

    <div id="decoder">
    <p id="part-of-speech-decoded"></p>
    <p id="case-decoded"></p>
    </div>
    </body>
    </html>

Obviously, it is not correct by a long shot and the formatting is terrible (I am very new to coding), but I hope you can see what I am trying to do. So I want my function to search if p id = "noun", then when the div containing p id="noun" is clicked, I want the word "Noun" to show up in .

Any help would be appreciated!

Aucun commentaire:

Enregistrer un commentaire