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. Commented Jan 11, 2016 at 2:42
  • 2
    Complex Selectors are resource heavy so this is faster: var textValue = document.getElementById("allowances").firstChild.innerHTML; Commented 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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.