How to get inner text of a DIV controller using java script?
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.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With