Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get innertext of a DIV using javascript? [duplicate]

How to get inner text of a DIV controller using java script?

like image 305
Ajeesh Ajayan Avatar asked Apr 09 '13 14:04

Ajeesh Ajayan


2 Answers

The short answer:

document.getElementById("id-of-div").innerText

The long answer, given that you've tagged the question with asp.net-mvc-3, is that this will be run in the browser, not on the server (where ASP.NET runs). There is no immediate way to get content from the browser to the server without sending a request. I'm guessing that you may want to make an ajax call to a new controller action from the page, but this depends on when the text changes, and what you want to do with it.

like image 158
harriyott Avatar answered Oct 12 '22 11:10

harriyott


Suppose you have a div declared as:

<div id="someDiv">
  some content goes here
</div>

You can get its value by:

// javascript
document.getElementById("someDiv").innerHTML
// jquery
$("#someDiv").html()
like image 43
von v. Avatar answered Oct 12 '22 12:10

von v.