Get query string parameter using JavaScript

Following code will help in fetching the value of a query string parameter.

function GetQueryStringParameter(parameter) {
    var search = location.search.substring(1);
    var queryStringParameters = JSON.parse('{"' + decodeURI(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}')
    return queryStringParameters[parameter];
}

Usage:

If URL is http://server/page.html?id=1

Then usage would be GetQueryStringParameters(“id”) which would return 1

Change new item text in SharePoint

The following script changes the “new item” link button in SharePoint view form to whatever we desire.

Add either of the script to content editor web part.

Plain JavaScript version: (This code assumes that there is only one “new item” text in the entire page.)

<script>
    document.addEventListener("DOMContentLoaded",
        function () {
            ExecuteOrDelayUntilScriptLoaded(function () {
                var ReRenderListView_old = ReRenderListView
                ReRenderListView = function (b, l, e) {
                    ReRenderListView_old(b, l, e)
                    changeText()
                }
            }, "inplview.js")
            changeText()
        }
    );

    function changeText() {
        var element = document.querySelector('#idHomePageNewItem span:nth-child(2)')
        element ? (element.innerHTML = "Add item") : null
    }

</script>

jQuery version: (This code can replace any number of “new item” text)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>

<script>
    $(document).ready(function () {

        var spans = document.getElementsByTagName("span");
        for (var i = 0; i < spans.length; i++) {
            if (spans[i].innerHTML == "new item") {
                spans[i].innerHTML = "add item";
                break;
            }
        }

    });

</script>

Source: sharepoint.stackexchange.com

Hide SharePoint list column

Sometimes we need to hide specific SharePoint columns in a list view webpart. The following code will help with that.
Make sure this code is placed in a JS file and referenced using JSLink webpart property.
Just replace the HideColumn function’s array parameters [“Title”, “Created By”] with necessary column’s display names.

(function () {
    var overrideCurrentContext = {};
    overrideCurrentContext.Templates = {};
    overrideCurrentContext.OnPostRender = PostRenderer;
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCurrentContext);
})();

function PostRenderer(ctx) {
    HideColumn(["Title", "Created By"],true);
}

function HideColumn(columns, hideOnlyHeader) {
    columns.forEach(function(columnName) {
        headerParentFirstNode = document.querySelectorAll("[displayname='" + columnName + "']")[0];
        if (headerParentFirstNode != undefined) {
            var header = headerParentFirstNode.parentNode;
            header.style.display = "none";
            if (!hideOnlyHeader) {
                var index = [].slice.call(header.parentNode.children).indexOf(header) + 1;
                for (var i = 0, cells = document.querySelectorAll("td:nth-child(" + index + ")"); i < cells.length; i++) {
                    cells[i].style.display = "none";
                }
            }
        }
    });
}