How to get the text from a DIV tag using JavaScript (no jQuery)

Using jQuery you can do many thing easily but sometimes you may not need to use jQuery for a small Application.

Okay then without using jQuery how can i get the text from a DIV tag?.

Its very simple you can get the text from a DIV tag using Javascript without  using any library like jQuery etc.,

Here is the code:


You may tried yourself to get the text from a DIV tag using ‘.value’ but actually you should use ‘.innerHTML’

Here is the example:

<script type="text/javascript">
function test() {
var t = document.getElementById('superman').innerHTML;
<input type="button" value="show text" onclick="test()" />
<div id="superman">This is the text from a div</div>

I hope this would have helped you in a critical situation.

About the Author


Software Engineer, Blogger etc., Visit my Youtube channel - <a href="">Click Here</a>

Leave a Reply

Your email address will not be published. Required fields are marked *