Jump to content

Javascript - Adding more than 1 item to CreateTextNode?

Baeger

I have this here and all I'm wondering is under

`document.createTextNode(addLocation.name);` 


How do I add more than one item? For example, would it work if i did
     

`document.createTextNode(addLocation.name, addLocation.description)`?


below is the full code for my function, it's meant to grab a bunch of different fields from localstorage and put them into different HTML elements in the same div but right now it only does 1 of the fields (the name, called "name" as a variable)

  function locationcardload(){
    
    var allLocations = document.getElementById("locationList");
    ;
    
    
    rawTxt = localStorage.getItem("locations")
    LocationArray = JSON.parse(rawTxt);
    ;
    
        for (var x=0; x<LocationArray.length; x++) {
        var addLocation = LocationArray[x];
        var additem = document.createElement("div")
       
        
        additem.classname = "icon";        
        additem.className = "item";
    ;
        var LocListText = document.createTextNode(addLocation.name);
            additem.appendChild(LocListText);
            allLocations.appendChild(additem);
          }
    }

 

About me:  23 Year old Software Developer from Wales, UK.  PC gamer and occasional Xbox Series X gamer (fanboy in recovery lol).  I stream occasionally as a hobby. 

The Rigs/Specs

 

KONAN (Main Rig): 
 

Spoiler

 

CPU: Intel Core I7-10700K

Case: Phanteks Enthoo Evolv X Digital Midi Tower Glass Gaming Case - Gunmetal Grey

Motherboard: Asus ROG Strix Z490-F Gaming (Socket LGA 1200) DDR4 ATX Motherboard

GPU: Gigabyte GeForce RTX 3070 Gaming OC 8GB GDDR6 Graphics Card

RAM: Team Group Vulcan Z T-Force 48GB (2x8GB & 2x16GB) DDR4 PC4-25600C16 3200MHz

PSU: Corsair HXi Series HX850i

Storage: M.2, SATA SSD, Array of 6TB HDDs, etc etc. 

 

CASWYN (Old Main Rig - Retired):

Spoiler

CASWYN (Main Rig):  i7 6700k @4.4Ghz, AsRock Z170 Pro4 Motherboard, Nvidia GeForce GTX 1080, 16GB Kingston HyperX Fury Black Series (2133MHz, DDR4) Array of several Hard Drives totaling to 9TB, Samsung 840 120Gb SSD (Boot drive)  Ask for other stuff where relevant

 

CLESEK (Laptop):

Spoiler

Dell Inspiron 7559 Gaming Laptop - i7-6700HQ, 12GB DDR4 RAM, GeForce GTX 960m, ADATA 128GB SSD, 1TB Standard HDD

 

Link to comment
Share on other sites

Link to post
Share on other sites

I would add all the information you want in the text node in an array and then loop it creating it as you go.

 

var data = ["A name", "A description"]
var string = "";
for(i = 0; i < data.length; i++)
{
 string = string + (data[i] + " ");
}
var t = document.createTextNode(string);
document.body.appendChild(t);
}

But you where almost right you would do

 

document.createTextNode(addLocation.name + addLocation.description);

 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×