For the latest updates, send a blank email to our SUBSCRIPTION ADDRESS
HEADLINES | CLASSIFIED | SPORTS | FORUM | BUSINESS | ENTERTAINMENT
Vol. 1, Issue 9
The News Organ of Liberty City
Thursday October 18th, 2001
Seplogo.gif
" Yesterday's News Today "

MediaWiki:Gadget-tabs.js: Difference between revisions

From Liberty Tree
Jump to navigationJump to search
No edit summary
Tags: Manual revert Reverted
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
document.addEventListener('DOMContentLoaded', function () {
$(document).ready(function () {
            document.body.addEventListener('click', function (e) {
  document.body.addEventListener('click', function (e) {
                var target = e.target;
    var target = e.target;
               
                // Ensure we get the parent <span> that contains class "show-div"
                var parentSpan = target.closest ? target.closest('.show-div') : null;


                if (parentSpan) {
    // Ensure the clicked element is an <a> inside a <span class="show-div">
                    e.preventDefault();
    if (target.tagName.toLowerCase() === 'a' && target.parentNode.className.indexOf('show-div') !== -1) {
                    var targetId = parentSpan.getAttribute('data-target');
      e.preventDefault(); // Prevent default anchor behavior


                    // Hide all divs
      var parentSpan = target.parentNode;
                    var contentDivs = document.querySelectorAll('.content');
      var targetId = target.getAttribute('href').substring(1); // Extract value after '#'
                    for (var i = 0; i < contentDivs.length; i++) {
                        contentDivs[i].classList.add('hidden');
                    }


                    // Show the targeted div
      // Remove "active" class from all spans
                    var targetDiv = document.querySelector('.content[data-id="' + targetId + '"]');
      var spans = document.querySelectorAll('.show-div');
                    if (targetDiv) {
      for (var i = 0; i < spans.length; i++) {
                        targetDiv.classList.remove('hidden');
        spans[i].classList.remove('active');
                    }
      }
                }
 
            });
      // Add "active" class to the currently selected span
        });
      parentSpan.classList.add('active');
 
      // Hide all divs
      var contentDivs = document.querySelectorAll('.content');
      for (var i = 0; i < contentDivs.length; i++) {
        contentDivs[i].classList.add('hidden');
      }
 
      // Show the targeted div by selecting its data-id
      var targetDiv = document.querySelector('.content[data-id="' + targetId + '"]');
      if (targetDiv) {
        targetDiv.classList.remove('hidden');
      }
    }
  });
});

Latest revision as of 15:27, 9 February 2025

$(document).ready(function () {
  document.body.addEventListener('click', function (e) {
    var target = e.target;

    // Ensure the clicked element is an <a> inside a <span class="show-div">
    if (target.tagName.toLowerCase() === 'a' && target.parentNode.className.indexOf('show-div') !== -1) {
      e.preventDefault(); // Prevent default anchor behavior

      var parentSpan = target.parentNode;
      var targetId = target.getAttribute('href').substring(1); // Extract value after '#'

      // Remove "active" class from all spans
      var spans = document.querySelectorAll('.show-div');
      for (var i = 0; i < spans.length; i++) {
        spans[i].classList.remove('active');
      }

      // Add "active" class to the currently selected span
      parentSpan.classList.add('active');

      // Hide all divs
      var contentDivs = document.querySelectorAll('.content');
      for (var i = 0; i < contentDivs.length; i++) {
        contentDivs[i].classList.add('hidden');
      }

      // Show the targeted div by selecting its data-id
      var targetDiv = document.querySelector('.content[data-id="' + targetId + '"]');
      if (targetDiv) {
        targetDiv.classList.remove('hidden');
      }
    }
  });
});