Click to toggle with special effect

Similar Question:
How to detect a click outside an element?

 <ul id="rightNav">

      <li id="SettingOpt">
        <a href="javascript:void(0)">username<span class="fabShopSprite iRecentIcon iUserIcon"></span></a>
        <div class="userMenu">
          <ul>
            <li><a class="Setting" href="/">Settings</a></li>
            <li><a class="Setting lastShadow" href="/">Logout</a></li>
          </ul>
        </div>
      </li>

    </ul>

The menu is functioning correctly, but I want it to close when the user clicks outside of the block. Additionally, I would like to add a toggle effect that activates when clicking on #rightNavToggle wrap. The current toggle effect works, however, it does not close when clicking outside of the block. Another requirement is for the sub navigation to also close when its link is clicked. Using JavaScript.

$("#SettingOpt a").click(function() {
        var parent = $(this).parent();
        parent.toggleClass("selected");
        parent.find("div.userMenu").toggle();
      });

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

Generating a hyperlink within an HTML file for other HTML files that reside in the same directory as the angular framework

Currently, I am developing a website for my final HTML project at university. This project uses Angular as the main framework. The task is to create 4 articles as separate HTML pages and have the article.component.html file contain links to these pages. I ...

"Logging is not functioning properly for successful results when performing an AJAX

I have configured an AJAX post to a PHP page. When the PHP page echoes the result, the success callback is supposed to log it. However, the logging does not seem to be working as expected. JavaScript: $(function(){ $.ajax({ url : "http://XXX ...

What is the best method to choose the initial offspring of the primary brother or sister within a list item?

Is there a way to specifically target the nested li elements in my css selector? Check out the Demo li:first-child { background-color: rgb(236, 236, 236); list-style-type: none; margin-bottom: 3px; padding: 8px; } <ul> <li& ...

Extract the values of input controls in an HTML string

I have a C# code snippet like this: string str = "<input type=\"hidden\" id=\"taken\" value=\"BoboBobo\">\n<input type=\"hidden\" id=\"took\" value=\"BaboboBe\"" Is there a way to e ...

Can a hashmap variable be declared in HTML code?

Can a hashmap variable be set in HTML code? Here's an example: <form name="f1234"> <input type="text" name="map['foo1']" value="dog" /> <input type="text" name="map['foo2']" value="cat" /> </form> < ...

Refreshing the View in Ionic and AngularJS Using Controller UpdatesIn this tutorial, we will

As a newcomer to both Ionic and Angularjs, I am currently in the process of developing a simple Ionic app. The main functionality involves displaying a list of classes (sessions), allowing users to book or cancel a class by clicking on an icon, and updatin ...

Strategies for correctly referencing and filling nested schema structures

TL;DR How can I reference and populate subdocuments within the same collection in Mongoose? I have been attempting to populate a reference to a subdocument in my Mongoose schema for some time now. My main schema (MainSchema) contains arrays of locations a ...

Resizable icon next to inline element caused width adjustment

I have a group of individuals listed, each with two elements side by side: a "contact me" button (an 'a' element with a fontawesome icon) and a tag displaying the user type (span element). Some users do not have a tag, and when there is one prese ...

I am having issues with the drag and drop directives in AngularJS - they work fine on my computer's navigator, but they

I have successfully implemented drag and drop directives in angularJS, and they are functioning properly on my computer's web browser. However, when I tried to use the directives on my touch devices, they did not work. Should I make adjustments to my ...

Tips for launching different web browsers via hyperlinks?

My app has a link that I want mobile users from apps like LinkedIn to open in a browser such as Safari. I attempted this: <a href="safari-https://meed.audiencevideo.com">May open on Safari</a>' However, when I click the link, it opens i ...

Why isn't client-side validation in ASP.NET Web Forms working when the field is filled via jQuery?

Within my ASP.Net WebForm, I have a mandatory field named Address. This particular field is filled in using jQuery based on the value entered into the Location field. Upon clicking the submit button without completing any fields, the client side validatio ...

SweetAlert2 not displaying properly in Ionic6 - troubleshooting the issue

My current project is an Ionic 5 Angular project with SweetAlerts2 popups. Recently, I decided to upgrade to Ionic6 and encountered an issue where the SweetAlerts2 popups are not displaying correctly. The alert seems to only show up in the header, leaving ...

Issue with setting a cookie using Node.js Puppeteer: cookie not being set as expected

I'm facing an issue with setting a specific cookie in the browser using Puppeteer. After executing the code to set the cookie and then displaying all the cookies on the page through console.log, the new cookie is not visible. The code I am running is ...

`Center the image on top of the text`

Currently, I am working with Bootstrap 4 to create a component that includes two tiles. Each tile has an icon image on the left side and a hyperlink on the right side. On desktop view, the tiles should be displayed horizontally and vertically centered. How ...

Retrieve a collection of elements that have been transferred from a Python file (using Django) to an HTML file, and then to JavaScript, all within the same webpage

Below is the Python code I have written: def index(request): body=list(Body.objects.all()) loads=list(Load.objects.all().order_by('length')) badLoads=[] goodLoads=[] for load in loads: if load.length>body[0].length ...

Is the parallax effect achieved by stacking one div on top of another div?

Here is a sample of my HTML code: <div id="a" class="panels">FIXED PANEL</div> <div id="b" class="panels">Scrolling-Panel 1</div> <div id="c" class="panels">Scrolling ...

Efforts to toggle visibility of icons in React

One issue I encountered is with the Navbar in mobile mode, where the icons are covering the menu. Refer to the image for a visual representation of the problem. https://i.sstatic.net/7eNeg.png To address this issue, my plan is to hide the icons when the ...

the function is not correctly displaying elements on the page through JavaScript

I'm facing an issue with the code provided - while the Navbar is being rendered, the h1 and img elements are not displaying anything. Upon inspection, it seems like the values inside these elements are not available. I tried debugging by logging to th ...

The socket context provider seems to be malfunctioning within the component

One day, I decided to create a new context file called socket.tsx: import React, { createContext } from "react"; import { io, Socket } from "socket.io-client"; const socket = io("http://localhost:3000", { reconnectionDela ...

If the source of the image is labeled as '(unknown)', then swap it with 'missing.png'

When an image is not provided in my CMS database, it currently produces an img src="(unknown)". I am looking for a way to use JavaScript to change this to img src="/images/missing.png". As someone who is new to JS, I have attempted various hacks but none ...