Windows Dev Center

WinJS.Utilities.toggleClass function

Applies to Windows and Windows Phone

Toggles (adds or removes) the specified class on the specified element. If the class is present, it is removed; if it is absent, it is added.

Syntax


var htmlElement = WinJS.Utilities.toggleClass(e, name);

Parameters

e

Type: HTMLElement

The element on which to toggle the class.

name

Type: string

The name of the class to toggle.

Return value

Type: HTMLElement

The element.

Examples


<div id="div1"></div>
<script type="text/javascript">
    var firstElement = document.getElementById("div1");
    WinJS.Utilities.addClass(firstElement, "testClass");
    var element = WinJS.Utilities.toggleClass(firstElement, "testClass");
    // This returns false.
    var hasClass = WinJS.Utilities.hasClass(firstElement, "testClass");

    WinJS.Utilities.toggleClass(firstElement, "testClass");
    // This returns true.
    hasClass = WinJS.Utilities.hasClass(firstElement, "testClass");
</script>

Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1

Namespace

WinJS.Utilities

Library

Winjs.js

 

 

Show:
© 2015 Microsoft