1

This is my js code :

<script type="text/javascript">

var url = window.location.protocol + "//" + window.location.host + _spPageContextInfo.webServerRelativeUrl;
var pngPath = '/_catalogs/masterpage/assets/tools-banner.jpg'; 
var elem = document.createElement("img");
elem.src = url + pngPath;
elem.setAttribute("alt", "Banner");
document.querySelector("#banner").appendChild(elem);

</script>

when i test it in the browser console it work just fine , but when i put it in the of my master page it doesn't work should i load jquery? any solution ?

2

1 Answer 1

0

Did you end the script with tag? better copy your code in a text file ( remember not to add tag in the text file, just the code) and save it as .js file. Load the file in Style library and publish it.

Now in Master page add script tag <script type="text/javascript" src="link where javascript is loaded"></script>

1

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.