How to get the inner text of a DIV controller using java script?
P粉7901875072023-10-19 09:55:59
Short answer:
document.getElementById("id-of-div").innerText
Considering that you've tagged your question with asp.net-mvc-3, the long answer is that it will run in the browser, not on the server (the one running ASP.NET). There is no way to immediately get content from the browser to the server without sending a request. I guess you might want to make an ajax call to the new controller action from the page, but that depends on when the text changes and what you want to do with it.
P粉2773052122023-10-19 09:19:28
Suppose you have a div declared as:
some content goes here
You can get its value in the following ways:
// javascript document.getElementById("someDiv").innerHTML // jquery $("#someDiv").html()