Home  >  Q&A  >  body text

How to get the inner text of a DIV using javascript?

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

P粉809110129P粉809110129366 days ago849

reply all(3)I'll reply

  • P粉790187507

    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.

    reply
    0
  • P粉277305212

    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()

    reply
    0
  • P粉477605856

    P粉4776058562023-10-20 10:08:59

    How to contact

    reply
    0
  • Cancelreply