I have div.

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

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

Recommended Answers

All 3 Replies

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>

No problem!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.