Accessing the clandestine div via direct hyperlink

I have incorporated a toggle plugin from this website to display hidden divs.

Each hidden div is identified by a unique id. Is there a method to show a specific div using a direct link?

For instance, by entering domain.com/page.php#HiddenDiv2, it should display <div id="HiddenDiv2">

You can view my page here:

Answer №1

If you're looking to achieve a specific functionality, you can utilize both the jQuery ready event and the JavaScript onhashchange event. Below is a snippet demonstrating how this can be implemented:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Example Page</title>
    <style>
        .hidden {
            display: none;
        }
    </style>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <script>
        $(function() {
            showHiddenDiv();
            window.onhashchange = showHiddenDiv;
        });
        function showHiddenDiv() {
            $(window.location.hash).show();            
        }
    </script>
</head>
<body>
    <div id="div-1" class="hidden">Div 1</div>
    <div id="div-2" class="hidden">Div 2</div>
    <div id="div-3" class="hidden">Div 3</div>
</body>
</html>

To check browser compatibility for the onhashchange event, refer to the following link: http://caniuse.com/#search=onhashchange

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

Custom HTML select element not triggering the onchange event

I found a code snippet on https://www.w3schools.com/howto/tryit.asp?filename=tryhow_custom_select that demonstrates a custom select input with an onchange event. However, I am facing an issue where the onchange event does not get triggered when I change th ...

Tips for transforming information into JSON format

Imagine having a file with data in CSV or TXT format, such as: Name, Surname, Age, Occupation Gino, DiNanni, 19, Student Anna, Kournikova, 27, Programmer (Extra spaces have been added to enhance readability) The goal ...

What is the best way to create a clickable background for a modal window?

I am looking to add a chatbox feature to my website and have been utilizing Bootstrap Modal for this purpose. My goal is to keep the modal open even when the user clicks outside of it, while still allowing them to interact with the background of the websi ...

How can you style a two-item list in Material-UI React to display the items side by side?

I have a list that contains two items: 'label' and 'value'. This is the current layout: https://i.stack.imgur.com/HufX7.png How can I rearrange the items on the right to be positioned next to the label on the left? https://i.stack.im ...

Is there a way to execute my view function without refreshing the page?

Is there a way to execute my view function without the need to reload the page? views: def toggle_priority(request, id): object = Object.objects.get(id=id) object.priority = True object.save() #return HttpResponseRedirect('/') ...

Looking for assistance with CSS to properly align a dozen items

UPDATE: See the current layout in this JFiddle based on feedback received from others, still a few tweaks needed. In my setup, there are 12 divs housed within one container div. These 12 divs consist of 6 text components and 6 corresponding input fields. ...

How can I configure Grails to properly interpret my JSON PUT AJAX request?

In this Grails app, the form is set up in a standard way. <g:form url="[resource:myClass, action:'update']" method="PUT" > <fieldset class="form"> <g:render template="form"/> </fieldset> <fieldset c ...

Experience a seamless integration of playing videos in the background using HTML5 with responsive design

Looking for a CSS trick to create a video background that spans the full width of the browser and auto resizes with the browser size. It's essential that it plays on Safari, so please specify the supported video file types. ...

Prevent divs from jumping to a new line with the float property

I've been busy working on a responsive webpage and so far, everything is going smoothly. The only issue I'm facing is that when the browser window size decreases and reaches a certain point, the div elements jump to the next line. Take a look at ...

Unnecessary additional spacing caused by inline blocks in Firefox

On my webpage, I have organized my div elements using inline-block properties. Strangely, Firefox is adding extra spacing between two specific divs, while Safari and Chrome display the design consistently. Check out this example here. #main { display ...

What steps can I take to guarantee that both images and text adapt well to different screen sizes?

Is there a way I can organize my website to display 3 movies per row with the text centered relative to the image? Here is how it currently looks (the red box is just for reference, please ignore): https://i.stack.imgur.com/w2pgN.jpg Also, when I resize m ...

Having difficulties retrieving JSON data

I'm encountering an issue while trying to retrieve my JSON data using an AJAX request. JSON { "Ongoing": [ {"name": "meh"}, {"name": "hem"} ], "Completed": [ {"name": "kfg"}, {"name": "dkfgd"} ] } ...

Tips for changing color when hovering over elements in a CSS grid

I am currently attempting to incorporate a hover effect into this CSS grid, but I have not been successful in my efforts. I experimented with transition and opacity techniques, but they did not work as expected. Can someone please point out what I may be ...

CSS: elements that are only visible when positioned above specific elements

Can we create an element that is only visible above specific other elements? For instance, in the following code snippet, I want the .reflection element to be visible only above the .reflective elements (located at the top and bottom) and not visible on t ...

Trouble with margins on tr elements and borders in CSS and HTML

Here are my current findings: http://jsfiddle.net/62hKs/2/ What I desire to achieve: 1) Create a 15px margin between the two red boxes displayed 2) Modify the appearance of the 4 boxes so they resemble only 2, by eliminating the middle red line caused ...

Upon clicking, the Bootstrap dropdown button fails to open up

Recently while working on my Ruby on Rails project, I encountered an issue with implementing a dropdown button similar to the one on Bootstrap's site. Unfortunately, the button isn't functioning as expected and is throwing an error in the browser ...

"Why are all the rows from my query being returned in my HTML/PHP/AJAX code

I've been working on a webpage that allows users to input a minimum GPA in a textbox to search a database and display records of students who meet that specific criteria. The HTML code calls a separate PHP file and utilizes AJAX to call a function. Ho ...

Remove the list by conducting a comparison analysis

<html> <head> <title> Manipulating List Items Using JavaScript </title> <script type="text/javascript"> function appendNewNode(){ if(!document.getElementById) return; var newlisttext = document.changeform.newlist.val ...

"Fixing the position of a div on the Samsung Galaxy S8 navigation bar to

Here is the HTML code I am working with: <div class="app-bar"> <a href="#'>icon</a> <a href="#'>icon</a> <a href="#'>icon</a> <a href="#'>icon</a> </div>' ...

Which is the better choice: jQuery or AJAX?

After careful consideration, I have chosen to utilize jQuery for all of my client-side AJAX requirements. However, I find that there are numerous functions in jQuery that can accomplish the same task, such as $.post, $.get, $.ajax, and $.getJSON. What woul ...