Update a WebSite Properties in SharePoint 2013 Using JavaScript (JSOM)

You can use the SharePoint client object model to retrieve, update and manage data in SharePoint 2013. SharePoint makes the object model available in several forms.

  • .NET Framework redistributable assemblies.
  • JavaScript library.
  • REST/OData endpoints.
  • Windows Phone assemblies.
  • Silverlight redistributable assemblies.

This article shows how to perform basic operations using the JavaScript object model. You can add a reference to the object model using HTML <script> tags.

The following sections describe tasks that you can complete programmatically and they include JavaScript code examples that demonstrates the operations.


Open your SP Site in SharePoint 2013 Designer. Then select an Assets icon in the designer ribbon to add a JavaScript file.

After adding the JavaScript file the file is available in the SharePoint Site Assets Folder.

Go to the SP site page and add a new page to the SharePoint site.

After adding a page select an Insert button in the Ribbon Menu.

Then add a Content Editor Web part into the page.

Edit the WebPart and add a JavaScript file link to the content link.

Save the web part and save the page in site. Click the button.

List Created Successfully.

Source Code

  1. <div><button onclick=" updateWebSite ()">Click here to AddaFieldtoList</button></div>  
  2. <div id="displayDiv"></div>  
  3. <script type="text/javascript">   
  5. //This function loads the list and runs the query asynchronously   
  7. function updateWebSite()   
  8. {  
  9.    var siteUrl=”https://gauti.sharepoint.com/sites/sp”;  
  10.    var clientContext = new SP.ClientContext(siteUrl);  
  11.    this.oWebsite = clientContext.get_web();  
  12.    this.oWebsite.set_title('Updated Web Site');  
  13.    this.oWebsite.set_description('This is an updated Web site.');  
  14.    this.oWebsite.update();  
  16.    clientContext.load(this.oWebsite, 'Title''Description');  
  18.    clientContext.executeQueryAsync(  
  19.       Function.createDelegate(thisthis.onQuerySucceeded),   
  20.       Function.createDelegate(thisthis.onQueryFailed)  
  21.    );  
  22. }  
  24. function onQuerySucceeded(sender, args)  
  25. {  
  26.    alert('Title: ' + this.oWebsite.get_title() + ' Description: ' + this.oWebsite.get_description());  
  27. }  
  29. function onQueryFailed(sender, args)   
  30. {  
  31.    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());  
  32. }  
  33. </script>  
Thanks for readingmy article.