I have div.

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

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

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>