1

I have div.

<div>This is text in div1.</div>

How do i get the text written in div to variable in javascript ??

Edited by new_developer

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by JorgeM
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>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.