I've been struggling to find a solution to my problem despite days of research. After stumbling upon a similar Stack Overflow question (GetElementByID - Multiple IDs), I still can't seem to implement the solution into my code even after numerous attempts and variations. [DEMO]. Despite asking for help multiple times, I keep receiving vague responses that don't provide any real assistance. The main issue at hand is: How do I create multiple IDs in the script to carry out different open-transitions?
/*!
* classie - class helper functions
* classie.has( elem, 'my-class' ) -> true/false
* classie.add( elem, 'my-new-class' )
* classie.remove( elem, 'my-unwanted-class' )
* classie.toggle( elem, 'my-class' )
*/
/*jshint browser: true, strict: true, undef: true */
/*global define: false */
(function (window) {
'use strict';
// class helper functions from bonzo https://github.com/ded/bonzo
function classReg(className) {
return new RegExp("(^|\\s+)" + className + "(\\s+|$)");
}
// classList support for class management
// although it sucks because it only accepts one class at a time
var hasClass, addClass, removeClass;
if ('classList' in document.documentElement) {
hasClass = function (elem, c) {
return elem.classList.contains(c);
};
addClass = function (elem, c) {
elem.classList.add(c);
};
removeClass = function (elem, c) {
elem.classList.remove(c);
};
} else {
hasClass = function (elem, c) {
return classReg(c).test(elem.className);
};
addClass = function (elem, c) {
if (!hasClass(elem, c)) {
elem.className = elem.className + ' ' + c;
}
};
removeClass = function (elem, c) {
elem.className = elem.className.replace(classReg(c), ' ');
};
}
function toggleClass(elem, c) {
var fn = hasClass(elem, c) ? removeClass : addClass;
fn(elem, c);
}
var classie = {
// full names
hasClass: hasClass,
addClass: addClass,
removeClass: removeClass,
toggleClass: toggleClass,
// short names
has: hasClass,
add: addClass,
remove: removeClass,
toggle: toggleClass
};
// transport
if (typeof define === 'function' && define.amd) {
// AMD
define(classie);
} else {
// browser global
window.classie = classie;
}
})(window);
/**
* main.js
* http://www.codrops.com
*
* Licensed under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*
* Copyright 2014, Codrops
* http://www.codrops.com
*/ (function () {
var bodyEl = document.body,
content = document.querySelector('.content-wrap'),
openbtn = document.getElementById('open-button'),
closebtn = document.getElementById('close-button'),
isOpen = false;
function init() {
initEvents();
}
function initEvents() {
openbtn.addEventListener('click', toggleMenu);
if (closebtn) {
closebtn.addEventListener('click', toggleMenu);
}
// close the menu element if the target isn't the menu element or one of its descendants..
content.addEventListener('click', function (ev) {
var target = ev.target;
if (isOpen && target !== openbtn) {
toggleMenu();
}
});
}
function toggleMenu() {
if (isOpen) {
classie.remove(bodyEl, 'show-menu');
} else {
classie.add(bodyEl, 'show-menu');
}
isOpen = !isOpen;
}
init();
})();
Despite having some insights,
var bodyEl = document.body,
content = document.querySelector('.content-wrap'),
openbtn = document.getElementById('open-button'),
closebtn = document.getElementById('close-button'),
isOpen = false;
You will notice two sets of gray dots on the page, with each set opening different boxes when clicked. Instead of this behavior, I want the first set of dots to only open the first box and the second set to open the second box, without any overlap. It seems like modifying the JavaScript portion mentioned above could solve this issue, but I'm unable to make it work. Can someone with expertise guide me through this process? Please provide a straightforward solution without unnecessary explanations.
I am in desperate need of assistance as I've encountered lengthy responses with no clear resolution. This task should be simple for those experienced in the field, and I believe there is a proven solution!