Skip to content

Instantly share code, notes, and snippets.

@bitkorn
Last active October 27, 2016 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitkorn/fe1061cfc30c9cd2bd15cc7d921cd10b to your computer and use it in GitHub Desktop.
Save bitkorn/fe1061cfc30c9cd2bd15cc7d921cd10b to your computer and use it in GitHub Desktop.
toggle W3.CSS dropdown with jQuery
function toggleW3(id) {
var toggleme = $("#" + id);
toggleme.css("z-index", 5);
if (!toggleme.hasClass("w3-show")) {
$("#" + id).addClass("w3-show");
$("#" + id).css("z-index", "1");
$("#" + id).removeClass("w3-hide");
var elementId = "";
$(".w3-dropdown-content").each(function (index, element) {
elementId = $(element).attr("id");
if (elementId != id) {
$(element).addClass("w3-hide");
$(element).removeClass("w3-show");
}
});
} else {
$("#" + id).addClass("w3-hide");
$("#" + id).removeClass("w3-show");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment