get value from div
I have div.
<div>This is text in div1.</div>
How do i get the text written in div to variable in javascript ??
11 Months Ago
Last Updated
Related Article: JavaScript Return value
is a JavaScript / DHTML / AJAX discussion thread by knitex that has 1 reply, was last updated 1 year ago and has been tagged with the keywords: dom, javascript.
new_developer
Junior Poster in Training
51 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Assign the div an ID then access it within the javascript code. For example...
<script type="text/javascript">
function getDivText(text) {
alert("Text = " + text);
}
</script>
<div id="div1">This is text in div1.</div>
<script type="text/javascript">
getDivText(document.getElementById("div1").innerHTML)
</script>
JorgeM
Senior Poster
3,997 posts since Dec 2011
Reputation Points: 294
Solved Threads: 543
Skill Endorsements: 115
new_developer
Junior Poster in Training
51 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
JorgeM
Senior Poster
3,997 posts since Dec 2011
Reputation Points: 294
Solved Threads: 543
Skill Endorsements: 115
Question Answered as of 11 Months Ago by
JorgeM