jQuery toggleClass example

Toggle class name on click in jQuery

by dshilkret

HTML

<div>
test
</div>

JavaScript

// find elements
var banner = $("#banner-message")
var button = $("button")

// handle click and add class
button.on("click", () => {
  banner.toggleClass("alt")
})
var hostweburl = "https://docintsp2016.discovertechnologies.com";
var addinweburl = "https://apps-cd3026e4f248fd.dtechwebapps.com/SharePoint-Add-in-REST-OData-CrossDomain";

// Load the required SharePoint libraries
$(document).ready(function () {
    //Get the URI decoded URLs.
   /* hostweburl =
        decodeURIComponent(
            getQueryStringParameter("SPHostUrl")
    );
    addinweburl =
        decodeURIComponent(
            // The query parameter is called SPAppWebUrl instead of SPAdd-inWebUrl because add-ins were originally called "apps".
            getQueryStringParameter("SPAppWebUrl")
    );*/

    // resources are in URLs in the form:
    // web_url/_layouts/15/resource
    var scriptbase = hostweburl + "/_layouts/15/";
   

    // Load the js files and continue to the successHandler
    $.getScript(scriptbase + "SP.RequestExecutor.js", getHostWebListsUsingREST);
});

function getHostWebListsUsingREST() {
    var executor;

    // although we're fetching data from the host web, SP.RequestExecutor gets initialized with the app web URL..
    executor = new SP.RequestExecutor(addinweburl);
    executor.executeAsync(
        {
            url:
                addinweburl +
                "/_api/SP.AppContextSite(@target)/web/lists/?@target='" + hostweburl + "'",
            method: "GET",
            headers: { "Accept": "application/json; odata=verbose" },
            
            success: successHandler,
            error: errorHandler
        }
    );
}

// Function to prepare and issue the request to get
//  SharePoint data
function execCrossDomainRequest() {
    // executor: The RequestExecutor object
    // Initialize the RequestExecutor with the app web URL.
    var executor = new SP.RequestExecutor(addinweburl);

    // Issue the call against the app web.
    // To get the...