Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 answers

573 users

How to get the value of the first child of tag element in JavaScript

Freaking Awesome WordPress Hosting
201 views
asked Jul 10, 2015 by avibootz
retagged Jul 10, 2015 by avibootz

2 Answers

0 votes
<!DOCTYPE html>
<html>
  
<head>
<style>
#div-id {
    background-color: cornflowerblue;
    width: 70px;
    height: 20px;
    padding: 10px;
}
</style>
</head>
  
<body>
  
<div id="div-id">div tag</div>
<p id="p-id"></p>
<script>
 
var txt = document.getElementById("div-id").childNodes[0].nodeValue;

document.getElementById("p-id").innerHTML = txt;  

/*
run:
  
div tag
  
*/

</script>
</body>
  
</html>

 





answered Jul 10, 2015 by avibootz
0 votes
<!DOCTYPE html>
<html>
  
<head>
<style>
#div-id {
    background-color: cornflowerblue;
    width: 70px;
    height: 20px;
    padding: 10px;
}
</style>
</head>
  
<body>
  
<div id="div-id">div tag</div>
<p id="p-id"></p>

<script>
 
var txt = document.getElementById("div-id").firstChild.nodeValue;

document.getElementById("p-id").innerHTML = txt;  

/*
run:
  
div tag
  
*/

</script>
 
</body>
  
</html>

 





answered Jul 10, 2015 by avibootz

Related questions

2 answers 189 views
1 answer 148 views
2 answers 6,966 views
1 answer 160 views
1 answer 170 views
...