how to get to the div value?

This alert(document.getElementById("Li1").innerHTML);


 shows                    <div id="divid">myName</div>

I also want to do                 alert(?????) to display             myName

how do i do that?

thanks
goodkAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeff DarlingDeveloper AnalystCommented:
alert(document.getElementById("divid").innerHTML); 

Open in new window

0
Jeff DarlingDeveloper AnalystCommented:
sample
<!DOCTYPE HTML>

<html>

<head>
  <title>Untitled</title>
  <script>
  function Getdivid(){
   alert(document.getElementById("divid").innerHTML);
  }
  function Getli1(){
   alert(document.getElementById("li1").innerHTML);
  }
  </script>
</head>

<body>
<div id="li1">
<div id="divid">myName</div>
</div>
<input type="button" onclick="Getdivid()" value="Get divid" />
<input type="button" onclick="Getli1()" value="Get li1" />
</body>

</html>

Open in new window

0
goodkAuthor Commented:
May be I did not explain,  the div is inside a div to make it unique as I have several on the page.


<div id="outerID_1">  <div id="innerID">thisname</div></div>

how to alert(  outerID_1.innerID  )  ????? to display thisname
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Jeff DarlingDeveloper AnalystCommented:
The way I would do it would be to create a document and populate that fragment into the document.

Now, here is a function,  that displays the name inside the li1div

<!DOCTYPE HTML>

<html>

<head>
  <title>Untitled</title>
  <script>
  function Getdivid(myli){
    var tempDoc = document.implementation.createHTMLDocument('');
    tempDoc.write(document.getElementById(myli).innerHTML);
    alert(tempDoc.getElementById("divid").innerHTML);
  }

  </script>
</head>

<body>
<div id="li1">
<div id="divid">John</div>
</div>
<div id="li2">
<div id="divid">Sara</div>
</div>

<input type="button" onclick="Getdivid('li1')" value="Get divid" />

</body>

</html>

Open in new window

0
Jeff DarlingDeveloper AnalystCommented:
Here is a version that works in IE9.  IE9 is a bit picky..

<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="X-UA-Compatible" content="IE=9" />
  <title>Untitled</title>
  <script>
  function Getdivid(myli){
    var tempDoc = document.implementation.createHTMLDocument("New Document");
    tempDoc.body.innerHTML =  document.getElementById(myli).innerHTML
    alert(tempDoc.getElementById("divid").innerHTML);
  }

  </script>
</head>

<body>
<div id="li1">
<div id="divid">John</div>
</div>
<div id="li2">
<div id="divid">Sara</div>
</div>

<input type="button" onclick="Getdivid('li1')" value="Get divid li1" />
<input type="button" onclick="Getdivid('li2')" value="Get divid li2" />

</body>

</html>

Open in new window

0
Rainer JeschorCommented:
Hi,

how about the function "textContent" ?

document.getElementById("divid").textContent;

Open in new window


Sample:
http://jsfiddle.net/EE_RainerJ/Ljpq3hwq/

HTH
Rainer
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jeff DarlingDeveloper AnalystCommented:
There is more than one div with the id divid.

another way would be to use jquery.

alert($('#li1').first('#divid').text());

Open in new window

0
goodkAuthor Commented:
thank you guys for your help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.