0

In SharePoint 2013 I added a div on a default.aspx like this:

<div id="myDiv"></div>

Then I added a Script Editor web part on the page, and added this JavaScript:

var element = document.getElementById('myDiv');
alert(element);

The alert box displays null. What am I doing wrong?

1 Answer 1

1

Make sure the Page is published and approved.

View the page source and make sure the element is present.

Try to place the script inside window.onload event

window.onload = function(){
    var element = document.getElementById('myDiv');
    alert(element);
}
1
  • brainwashed by new territory. forgetting the basics. Commented Jan 19, 2015 at 19:19

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.