Note that there are some explanatory texts on larger screens.

plurals
  1. POUnderstanding nodes and how to append
    primarykey
    data
    text
    <p>I've been working on a project that some other developers had started and I'm trying to understand the code while also completing the project. Currently what I have is some json with links and a url text (pretty much a quick description), what I need to do is on a button click I want to display each of the links with their correct text and make it a clickable link. The way this needs to be done is using nodes which I'm not 100% knowledgeable on. If I need to explain this more please let me know also I have provided an example of what I'm currently working with. Thanks</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8" /&gt; &lt;title&gt;JavaScript And JSON&lt;/title&gt; &lt;/head&gt; &lt;body bgcolor='#CED3F3'&gt; &lt;button onclick="appendUrl()"&gt;Append&lt;/button&gt;&lt;br&gt; &lt;br&gt;&lt;script id = "i"&gt; function category() //adding function with button click removes html page styling? { var category = { "content": [ { "links": "basic information", "urlText": "Basis Information System", "urlDesc": "portal for technology development, people search, a keyword search ." }, { "links": "http://site.com", "urlText": "Net", "urlDesc": "the entry page example" }, { "links": "http://newsgroups.com", "urlText": "Newsgroups", "urlDesc": "information internal newsgroups, usage, tools, statistics, netiquette" }, { "links": "http://site2.com", "urlText": "Another site", "urlDesc": "community for transfer of knowledge and technical information" }, { "links": "http://news.com", "urlText": " some news", "urlDesc": "place with news" } ] } &lt;/script&gt; &lt;script&gt; function appendUrl() { //there needs to be a loop here? var link = "needs to loop through links?" var node=document.createElement("LI"); var nodeA=document.createElement("A"); var textnode=document.createTextNode(); node.appendChild(nodeA); nodeA.appendChild(textnode); nodeA.href=(link); nodeA.target="_blank"; document.getElementById("i").appendChild(node); } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload