3

I need to get the text from a multi-line field in display mode on a custom form. SharePoint decides to wrap the text in an extra div which is not on the .aspx page which is causing the problem as I can not give it an ID.

The html is rendered as this:

< td class="ms-formbody" id="allowances" valign="top" width="400px"><div dir="">THIS TEXT HERE< /div >< /td>

When I use .innerHTML it comes with the < div> tag. InnerText returns nothing.

What is the best way to return only THIS TEXT HERE?

1 Answer 1

5

You can use queryselector to reach the text inside the div:

var textValue = document.querySelector("#allowances div").innerText;
2
  • Worked perfectly. Only thing is that I needed to change it to innerHTML.
    – Roland
    Jan 11, 2016 at 2:42
  • 2
    Complex Selectors are resource heavy so this is faster: var textValue = document.getElementById("allowances").firstChild.innerHTML; Jan 11, 2016 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.