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,039 questions

40,773 answers

573 users

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

Learn & Practice SQL


212 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 198 views
1 answer 152 views
2 answers 6,974 views
1 answer 169 views
1 answer 176 views
...