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

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);
}
  • brainwashed by new territory. forgetting the basics. – joym8 Jan 19 '15 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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