0
   

Javasctipt Problem with creating elements and appending everything

 
 
Reply Mon 7 Oct, 2013 12:42 pm
Hello:
I,m trying to write some code to create a a div with a class and and id. I believe I have that part correct, I then create a <p> element, I then create a text node to go inside the tag the issue is trying to append everything.
This is what I'm trying to do
var element = document.getElementsByClassName("creditCardSummary");

var parent= element.parentNode;

//create div

var newDiv = document.createElement("div");
newDiv.id "newcc";
newDiv.className = "creditCardSummaryWrapper";

//Create a paragraph tag
var para = document.createElement("p");
alert("here")
var node=document.createTextNode("CardNumber:cshadow Experation:monthyear");

//The monthyear and cshadow are variables that hold information I
//captured from a form successfully.

para.appendChild(node);

I can't figure out out how to append all this so div , class, id p and text show up.

This is really complicated I tried something like
parent.insertAfter(element, para); //I know something is missing.

Your help is greatly appreciated, thanks in advance
PH

  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 0 • Views: 1,229 • Replies: 1
No top replies

 
pamelaharper
 
  1  
Reply Mon 7 Oct, 2013 07:25 pm
@pamelaharper,
I also forgo to mention that the form information is in the script.
var newDiv = document.createElement("div");
newDiv.id "newcc";
newDiv.className = "creditCardSummaryWrapper";

//This takes care of appending itselt so newDiv will have an id and class
<div id="newcc " class="creditCardSummaryWrapper">
/*********************************************************/

//Create a paragraph tag
var para = document.createElement("p");

var node=document.createTextNode("CardNumber:cshadow Experation:monthyear");

para.appendChild(node);


//From my research this should work I'm have an issue with:
parent.insertAfter(para. newDiv, element);
I put an alert after it and it never hits it so I'm assuming its 'not working
and I'm not geting end result

//I have logically written this out and given a lot of thought
I've been struggling with it for a couple of days on ad off.


Thank You,
Sad



Thanks in advance
0 Replies
 
 

Related Topics

 
  1. Forums
  2. » Javasctipt Problem with creating elements and appending everything
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.06 seconds on 12/22/2024 at 09:45:37