Tips for automatically opening a specific section of a collapsible menu upon page load using a predetermined value

JSFiddle: http://jsfiddle.net/5qweu58f/4/

HTML (generated using XSLT):

<div id="dvExpProvHolder" class="hidOverflow innerDivCenter">
    <ul class="uSPStyle" id="uSPStyle">
        <li class="setRelative">
            <a class="tfLink clickMe current" title="Care" data-toggle=".tfLink1" id="current" href="javascript:void(0);"><img src="theImages/imgMenu.png" id="imgFirstM" class="imgExpCol" />Care</a>
            <ul class="uSPStyle uSPInner" style="width: 80%;">
                <li><a class="tfLink clickMe" title="This is sub" data-toggle=".tf1SLink1" href="javascript:void(0);">This is sub</a></li>
            </ul>
        </li>
        <li>
            <a class="tfLink clickMe" title="Breast Cancer" data-toggle=".tfLink2" href="javascript:void(0);"><img src="theImages/imgMenu.png" id="imgFirstM" class="imgExpCol" />BC</a>
            <ul class="uSPStyle uSPInner" style="width: 80%;">
                <li><a class="tfLink clickMe" title="OUR LINK" data-toggle=".tf1SLink2" href="javascript:void(0);">OUR LINK</a></li>
            </ul>
        </li>
        <li>
            <a class="tfLink clickMe" title="About" data-toggle=".tfLink3" href="javascript:void(0);">About</a>
        </li>
        <li>
            <a class="tfLink clickMe" title="Anxiety" data-toggle=".tfLink4" href="javascript:void(0);">Anxiety</a>
        </li>
        <li>
            <a class="tfLink clickMe" title="Services" data-toggle=".tfLink5" href="javascript:void(0);">Services</a>
        </li>
    </ul>
</div>
  • Why doesn't the first UL lose the current class when another UL is clicked? everything else works as expected.

  • The issue comes up when I would want the visitor to see BC > OUR LINK section which shows "This is for second link sublink 1" without having to come to the page and then click on it. But because they are all in one page, there is no way to do that out of the box. I was wondering if there is a way to specify a query string in the Url and use that to go directly to the sublink? For example: . The 2.1 would represent it is the second main menu and the first submenu. Is there any way to incorporate that into my Jquery script?

Answer №1

Building upon the ideas presented in the main question regarding extracting query string values using JavaScript (How can I get query string values in JavaScript?), this solution showcases how different methods can be implemented to parse window.location and respond accordingly to a query string parameter.

To illustrate this concept, a demo is provided below with a simulated URL instead of window.location, given that the example is contained within a protected frame. The showcased approach leverages URI.js, although several alternatives are available for consideration.

function displayOutput (data) {
  var element = document.createElement('div');
  element.innerHTML = data;
  document.body.appendChild(element);
}

document.getElementById('button-1').onclick = function () {
  displayOutput('Button 1 was clicked!');
};
  
document.getElementById('button-2').onclick = function () {
  displayOutput('Button 2 was clicked!');
};

//Extracting the "click" query string parameter to trigger a button click based on the specified ID.
//Utilizing a fabricated URL in place of window.location within this enclosed environment.
document.getElementById(URI('http://example.com?click=button-1').search(true)['click']).click();
<script src="https://cdnjs.cloudflare.com/ajax/libs/URI.js/1.16.1/URI.js"></script>

<button id="button-1">Button 1 - Clicked Automatically</button>
<button id="button-2">Button 2 - Not Auto-Clicked</button>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with downloading files in Internet Explorer is not functioning properly

I am encountering an issue in my Angular.js controller where downloading a CSV file works perfectly in Chrome but not in IE. The browser console log indicates: HTML7007: One or more blob URLs were revoked by closing the blob for which they were create ...

Utilize BotDetect in Angular js for advanced functionality

We are licensed to use BotDetect and now, we want to integrate it with Angular js. After searching on Google, I couldn't find a proper solution but stumbled upon angularjs-captcha, which seemed promising at first but didn't quite help me achieve ...

Creating Dynamic CSS Styling with Vendor Prefixes in Angular 2

I am exploring how to create a component in Angular 2 with two input arguments: colorOne and colorTwo. The goal is to fill a <div> with a gradient of these two colors. If I simply wanted to set the div background color to colorOne, I could achieve t ...

What causes discrepancies between jQuery set attributes and .html() output?

In an attempt to set attributes on HTML snippets, I am aiming to repopulate a form with previously entered values. Despite using .attr() to set the attributes, they do not appear after using .html(). For reference, I have provided a simple example here: h ...

When using TypeScript in Angular, the "debugger;" statement may encounter issues in the QA environment

Currently engaged in developing an angular application that involves working with multiple environments, I am encountering difficulties while attempting to set up debugging points using debugger; For compiling node_modules and running the server, I use th ...

Create a Material Design Lite Grid layout featuring cards that mimics the aesthetic of Google Keep

My current project involves using Django along with Material Design Lite to create a responsive layout. The cards I generate adjust their size based on the screen width. To demonstrate this, here is a snippet of the HTML code with some cards removed for r ...

Testing Your Angular 7 Code: Unit Testing Made Easy

I am currently working on developing unit tests for this angular script: export class DataService { private csrfToken: string = ''; private isContentShown: BehaviorSubject<boolean> = new BehaviorSubject(true); constructor(private h ...

JavaScript code that triggers a function when the mouse is moved over a description box on a

As a beginner in the field of Computer Science, I recently embarked on a project to create a website for sharing science articles with students. The goal is to spark curiosity and interest in science through this platform. One key feature I wanted to inclu ...

The compatibility issue between jQuery popover and AngularJS causes functionality disruptions

One clever trick with jQuery popover involves populating a hidden div with our data and instructing the clicked button to show a popover with that hidden div as its content. However, when dealing with multiple divs, we may encounter issues with classes. ...

Utilizing Angular Dependency Injection for Extending Base Services with Subclasses

My service setup includes a base service and two services that inherit from it: @Injectable({ providedIn: 'root' }) export class BaseService { foo(src?: string){ return `speaking from ${src || 'BaseService'}`; } } @Injectable ...

Search for a result based on a connection, but ensure that the association is not included in the final outcome when using

Basically, I'm trying to search for something in a table using the method include: [{ model, where }], but without actually including the model itself. I have two models, Part and Set, with a one-to-many connection. I am looking for Parts that are re ...

.NET 6 facing controller path value issues due to BeginForm

Since upgrading my app from .NET Framework 4.8 to .NET6, I have noticed a strange behavior with Html.BeginForm altering the slash to "%2F" in the controller path, making them unreachable. For example: <form action="/Admin/Report/Download ...

AngularJS - issue with directive functionality on dynamically inserted classes

Check out this plnkr - I've got a button that toggles the class toggled on the body element. I've also developed a directive to trigger an alert when the toggled class is applied to the body element, but for some reason it's not working. H ...

What steps should be followed to incorporate a horizontal scrollbar within the table's header?

I'm currently using Vue and Vuetify to create a unique layout that looks like this: https://i.stack.imgur.com/QBs3J.png The layout consists of a card with three rows: The first row displays the number of items and includes a search bar. The second ...

Locate the storage destination of a NodeJS module that has been installed

Examining the following code snippet from the grunt-template-jasmine-istanbul repository on GitHub; var DEFAULT_TEMPLATE = __dirname + '/../../../../grunt-contrib-jasmine/tasks/' + 'jasmine/templates/DefaultRunner.tmp ...

What are some solutions for resolving the issue of a neutralino white screen?

After setting up a new neutralino js application, I encountered an issue where upon running it with the 'neu run' command, all I see is a blank white screen. I tried using the CheckNetIsolation.exe ... command to troubleshoot the problem, but unf ...

Passing a single item from a list as a prop in Vue.js

Imagine having the following set of information in data: data: { todos: [ { id: 1, title: "Learn Python" }, { id: 2, title: "Learn JS" }, { id: 3, title: "Create WebApp" } ] } Now, I aim to send only the item with an id of 2 t ...

The PHP content form is malfunctioning and not processing email submissions properly, resulting in the PHP code being

Following a tutorial, I attempted to create a basic contact form using PHP. As a beginner in PHP, I found the process fairly straightforward, but encountered some bugs in the code. Upon integrating the code on my website, clicking the submit button redirec ...

Unlocking Worldwide Availability for Identifying URL Parameters

Is there a way to obtain global access to the current URL ID params? I am facing difficulty accessing the current URL ID in a child component within React. The ID is essential for querying a MongoDB database in my ChecklistTool component. Typically, I wou ...

Issue with IE 11: Including card image inside anchor tags in Bootstrap 4 causes unwanted white space

I'm having an issue with my Bootstrap 4 card markup where the image is wrapped inside an anchor tag. The problem arises when viewing it in IE 11, as there is a large white space underneath the image, while everything displays fine in Chrome, Edge, and ...