Steps to access the Link URL when the class name transforms to display as block:

I'm currently working on a function that needs to trigger a click on a link only if a specific classname is set to display: block;

Unfortunately, my coding skills are not advanced enough to accomplish this task.

Here is what I have so far: https://jsfiddle.net/thvinic/xesbvfkc/

if ($('hidden').is('display') == 'block') {
document.getElementById("urlx").click();
}
.hidden { display: block; }
<div id="HIDDENDIV" class="hidden">this is a div</div>

    <a href="https://www.google.com" id="urlx">Google go example!</a>
    
    <script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<script src="path-para-seu-script"></script>

Thank you for your assistance!😊👍

Answer №1

Make sure to check the .hidden property display using .css and within the click event on the link.

e.preventDefault(); // prevent the default click behavior

if ($('.hidden').css('display') == 'block') {
// check if .hidden display is set to block

$('#urlx').unbind('click'); // Unbind the click event to remove the preventDefault()

In the given example, when .hidden has display:none, the click action doesn't work. Change the display:none to display:block to enable the link to work properly.

$('#urlx').on("click", function(e){
e.preventDefault();
if ($('.hidden').css('display') == 'block') {
  $('#urlx').unbind('click');
  document.getElementById("urlx").click();
}
});
.hidden { display: none; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<div id="HIDDENDIV" class="hidden">this is a div</div>
<a href="https://www.google.com" id="urlx">Google go example!</a>

Updated! Automatic click: It will wait for 2 seconds before triggering the click!...

setTimeout(function(){
if ($('.hidden').css('display') == 'block') {
  document.getElementById("urlx").click();
}
},2000);
.hidden { display: block; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<div id="HIDDENDIV" class="hidden">this is a div</div>
<a href="https://www.google.com" id="urlx">Google go example!</a>

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

The use of DIV tags allows the element to be displayed in an inline

In my project, I decided to add three div tags. The first two are positioned next to each other with the third div tag placed below them. However, when I tried to insert a slideshow into the first div tag, all of the div tags ended up displaying as "block" ...

In Internet Explorer 11, border-radius creates a separation between elements

There is an issue with whitespace appearing around elements that have a border-radius larger than 0, but this only occurs in Internet Explorer. If using border-top-left-radius: 20px; and border-top-right-radius: 20px;: https://i.sstatic.net/MAKsx.png *W ...

Converting Excel VBA code to Javascript for use in Google Sheets: A step-by-step guide

Hello everyone, I am looking to convert a VBA code that I wrote into javascript and integrate it into Google Sheets. Does anyone have any suggestions on how I can accomplish this task? The VBA code in question is as follows: Sub Influencers_automacao() ...

I am facing an issue with file manipulation within a loop

I need to set up a folder with different files each time the script runs. The script should not run if the folder already exists. When I run the script, an asynchronous function is called and one part of this function causes an issue... This is my code : ...

Exploring the concept of JavaScript closures and the pitfalls of name clobber

Is it possible for variables defined inside an inner function with the same name as a variable in an outer function to be isolated from the outer variable? function() { var myTest = "hi there"; ( function( myLocalTest ) { myLocalTest = "go ...

Live Node.js and Next.js apps experiencing issues with functioning websockets

Within my nodejs backend at https://backend.example.com, the following code resides in my server.js file: const WebSocket = require('ws'); const server = new WebSocket.Server({ port: 7500 }, () => { console.log('S ...

Adjust the height of a div to match the tallest element in the same row using jQuery and Javascript

I need to display multiple rows of products, each row containing 4 products. The code snippet below shows an example with only 1 product. To create a row with 4 products, the code for <div class='col-xs-6 col-sm-3 col-md-3'> needs to be rep ...

What is the best way to extract a JSON string from the login PHP response?

I am working on creating a basic website along with an Android application that both retrieve data from the same database. While I have no issues in dealing with Android, I am facing difficulty in handling JSON strings in HTML. How can I fetch the JSON res ...

Can a filter be eliminated from a CSS file in a modified CSS file?

Currently, I am facing a dilemma with a CSS rule in my file. The rule in question looks like this: .someElement { filter:gray(enabled=true) alpha(opacity=50); -ms-filter:"gray(enabled=true) alpha(opacity=50)" } This specific rule is causing some ...

Organizing an Ordered List of Items into Alternating Columns Using HTML

I am in the process of developing a responsive HTML design to showcase an array of organized data. For smaller screens, the layout will consist of a single column displaying items sequentially. However, on larger screens, the design should adapt to featur ...

Automatically change div background image based on window resizing

.step-1-4 { background:url('../images/gadget-4-sprite.png') no-repeat; width:950px; height:70px; margin-left: 15px; } The code above sets the CSS for a div containing a background image. The dimensions of the div match that of the imag ...

Is there a way to set a default value for the map function?

Currently utilizing React.js with the following code snippet: myArray.map(variable=>({value: variable.value, label: variable.label})) It's working well for the most part, but occasionally encountering this issue: TypeError : myArray is null Any s ...

Horizontal alignment of Inline Block Elements is not achieved

Having trouble with the alignment of a form on a test site? Check out the form located under the div#search-bar. If you inspect the element, I have applied the following CSS: div.nf-field-container { width: 201px; display: inline-block; margin: ...

Leverage the power of Node.js by utilizing http.get along with

I have been working on integrating a library (available here) into my project, which is capable of generating QR codes and various other types of codes. My current issue revolves around making a request where I can access both the req and res objects in o ...

Ways to arrange objects to fill up space in a specific sequence

My HTML document contains two child HTML elements within the parent HTML. The parent HTML has a div with a class of .page, which is a large area for the children to occupy. Both children are of the same size and I need them to spawn in a specific order; fo ...

How can I resolve the issue with the HTML/CSS footer not functioning properly on Safari for iPhone in my mobile site?

Struggling with a mobile website issue here. The client wants text-based buttons/links at the bottom, so I added them in, but my skills with size percentages are a bit rusty. I need these buttons to line up horizontally and adjust their width accordingly ...

submit multiple images simultaneously

I'm attempting to upload multiple photos simultaneously using XMLHttpRequest. if(files.length <= 6) { for(var i = 0; i < files.length; i++) { var formData = new FormData(); formData.append('action', 'upload ...

Unexpected firing of jQuery blur event upon page load rather than during the expected time

Currently, I am working on a project that involves form validation using jQuery. One element I am focusing on is the email field, where users will input their emails. I want to ensure that the email input is checked once it has been filled out. My initial ...

Tips for accurately dissecting a PDF document to determine the status of checkboxes

Looking for a solution to parse PDF forms on the server side, I have experimented with various node.js modules including pdf2json, hummus, and node-pdftk. While I have successfully retrieved all text fields, I am facing issues when it comes to extracting c ...

Creating a route provider tailored to specific user roles

I have a rather straightforward requirement. There are 3 different User Roles: CATUSER LICUSER ALLUSER The User Role value is stored in the $rootScope.userRole variable. The User Role is predefined before the AngularJS application starts as the Angula ...