Basic Help On inserting arrays in javascript into paragraph element in HTML -


i have simple html:

<h3 id='target'>    <p> <!--insert javascript joined array here ---> </p> </h3> 

and simple javascript:

var letters = ["a", "b", "c", "d"];  var joinedletters = letters.join(", , ");  var getelement = document.getelementbyid("target").firstelementchild;  getelement.innerhtml = joinedletters; 

problem:

it comes out formatted in h3 (text bold) , not p. object insert joined array in paragraph element. don't know if it's possible. help/explanation appreciated. thanks!

update:

i catch mistake, guess not time. all! made necessary changes:

<h3>joined</h3> <p id='target'><!--insert joined array here--></p> 

and js (not including array js above). seems outcome wanted:

var getelement = document.getelementbyid("target").innerhtml; document.write(getelement = joinedletters); 

curious:

how come if write code above this, duplicate of array appear?:

var getelement = document.getelementbyid("target"); document.write(getelement.innerhtml = joinedletters); 

and, seems inserted array not editable css (all links established):

p {color: red} 

i'm thinking has document.write function. once again! great help, great help! :)

final answer:

var getelement = document.getelementbyid("target"); getelement.innerhtml = joinedletters; 

this house clean.

the paragraph bold because it's wrapped in h3 tag. either rid of h3 tag or write css like

h3#target > p { font-weight:400; } 

not sure if trying retain quotes in output can this..

var joinedletters = "'" + letters.join("','") + "'";  // 'a','b','c','d' 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

django - CSRF verification failed. Request aborted. CSRF cookie not set -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -