We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,695 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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 ??

2
Contributors
3
Replies
3 Days
Discussion Span
11 Months Ago
Last Updated
4
Views
Question
Answered
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

Thanks man

new_developer
Junior Poster in Training
51 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

No problem!

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

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0648 seconds using 2.73MB