Sometimes it is necessary to remove all the nodes from the navigation (quicklaunch or top navigation). One reason could be that the navigation should be set different from the original after the site was created. To remove all the nodes by JavaScript the following script could be used.

<script type="text/javascript" language="javascript">

	var clientContext = null;
    var navigationNodeCollection = null;
    var nnci = null;
	
	function removeNavigationNodes() {
        this.clientContext = new SP.ClientContext.get_current();

        if (clientContext != undefined && clientContext != null) {
            var web = clientContext.get_web();

            // Get the Quick Launch navigation node collection.
            // this.quickLaunchNodeCollection = web.get_navigation().get_quickLaunch();
            
            // Get the Top Navigation navigation node collection.
			this.navigationNodeCollection = web.get_navigation().get_topNavigationBar();

			this.clientContext.load(this.navigationNodeCollection);
			this.clientContext.executeQueryAsync(
				Function.createDelegate(this, this.onQuerySucceeded), 
				Function.createDelegate(this, this.onQueryFailed));
        }
	}
	
    function onQuerySucceeded() {
		// remove all nodes from the navigation node
		for(var i = this.navigationNodeCollection.get_count() - 1; i >= 0; i--) {
            this.navigationNodeCollection.get_item(i).deleteObject();
		}

		this.clientContext.executeQueryAsync(
			Function.createDelegate(this, this.onQuerySucceededPartTwo), 
			Function.createDelegate(this, this.onQueryFailed));

	}

    function onQuerySucceededPartTwo() {
        alert("Nodes removed");
    }

    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }

    function runCode() {
		removeNavigationNodes();
    }

</script>

<input id="Button1" type="button" value="Set Navigation" onclick="runCode()" />

Take the script and save it as a file. Copy this file to the SiteAssets library in your SharePoint site. Create a new page and add a Content Editor webpart on the page. In the properties of the webpart enter the complete url to the script file you saved in the SiteAssets library.

Advertisements