Click event binding with getter/setter in jQuery

Is there a way to replace this timeout with a getter/ setter? I want the images in the filter gallery to be sorted based on the globalVariable value when a user clicks on a section.

Currently, I am using a timeout which stops working after one click. I have looked at this question for guidance, but I am still struggling to grasp it. You can find the codepen here. What would be the most effective approach to achieve this?

Part of the Code: /* Generate all items on "All", then generate the ones that match the globalVariable on click */

$grid.revealItems(GenerateItems(8));

/*This click function does not repeat, so no more items load after the second click*/
var variableSet = document.getElementById("filterList");
variableSet.addEventListener('click', runFunction);

function runFunction(){setTimeout (function(){
$grid.revealItems(GenerateItems(4));
}, 1000)}

 /* Filter on Click */
  $(document).on("click", ".filter-item", function clickFilter() {
    $(".filter-item.active").removeClass("active");
    $(this).addClass("active");
    var f = $(this).data("f");
    //Global Variable 
    globalVariable = $(this).attr('name');  

Answer №1

Utilizing the async/await feature in a function requires adding 'async' before the function definition and 'await' before the function call.

async function GenerateItems(max){ 

It's unclear what purpose this serves, so more information may be needed. In the provided code snippet, 'await' should precede an API or function call that returns a callback or promise. However, it does not appear to do either in this case.

await if (globalVariable != "ImgsName") continue;

For reference, here is a sample of asynchronous await code block:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function

If you provide more details about your intentions with the await line, we can offer further assistance.

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

triggers an unexpected error in console.log

I need help with the following code: function printName(obj) { console.log(obj.name); } printName({ name: "myName" }); (function displayError(errorMsg){ console.log(errorMsg); })("Error"); However, when I try to run this code, I am encountering a T ...

Choosing an input option after the second ajax call is finished with JQuery

I'm fetching data from MySQL to PHP using AJAX. I am trying to implement an edit feature on my website within a modal window. The select input with options (subcategories) is loaded via AJAX after the radio input categories are loaded by a previous AJ ...

Invoke a server-side function via JSON data

Need help with calling a server-side method from JSON. Below is the code I currently have: SERVER SIDE: [WebMethod] private void GetCustomer( string NoOfRecords) { string connString = "Data Source=Something;Initial Catalog=AdventureWorks;Trusted_Con ...

The addition of a slash between the hashtag and the anchor name by Fullpage.js is causing conflicts with ng-include

My experience with using fullpage.js on a simple site alongside angular directives has been met with an issue. When including a .phtml file, the anchor functionality of fullpage.js stops working as it adds a slash before and after the anchor name. UPDATE ...

Stop a second ajax request while the first one is in progress

Despite the abundance of questions on Stack Overflow addressing this issue, I still can't find a solution. Here is the jQuery code snippet: function _get_activities_ajax() { $(".activity-accordian h3").click(function() { var catrgory ...

Tips for shuffling the positioning of three out of four divs when the page is refreshed

Below is the code snippet I am currently working with: <div class="allContent"> <div class="content"></div> <div id="headline"></div> <div class="content"></div> <div class="content"></div ...

Ways of extracting specific information from a JSON file with the help of jQuery

I am currently attempting to parse a JSON file that is stored locally on my system using jQuery. I am specifically interested in retrieving certain data from the file, which is structured like this: {"statements":[{"subject":{"uriString":"A","localNameIdx ...

Having trouble with submitting the second stage of a multi-step form through Ajax technology

I'm currently tackling a multi-step form project using JavaScript, specifically focusing on submitting the second step of the form via Ajax. I've taken the initiative to create a distinct JavaScript file titled ajaxRequest.js to manage the Ajax r ...

Can the hasClass() function be applied to querySelectorAll() in JavaScript?

As a beginner in javascript and jquery, I recently attempted to manipulate classes using the following code snippet: if ($(".head").hasClass("collapsed")) { $(".fas").addClass("fa-chevron-down"); $(".fas&qu ...

Is there a way to trigger a click event on an href using asp code behind?

Is there a way to programmatically trigger a click event on the href "shipping_question_ID_product_received_as_ordered_link" from the code behind of an ASP form? This href triggers a complex function in jquery when clicked by the user. I need to simulate ...

Issue with loading dynamic content on a webpage using HTML and JavaScript through AJAX

I am currently using the jQuery UI Tabs plugin to dynamically load HTML pages through AJAX. Here is the structure of the HTML code: <div id="tabs"> <ul> <li><a href="pageWithGallery.html" title="pageWithGallery">Gallery< ...

Optimizing Chrome's Precious Load Time

Encountering issues with Chrome browser auto-filling passwords, usernames, etc. Creating a problem where input field validation for emptiness is not possible in Chrome while it functions correctly in other browsers. $(document).ready(function() { ...

Prevent PHP script from running during an AJAX request

Here is a brief overview of how my small application functions: users are prompted to input a URL into a simple text field. Upon any changes made to the input, my script attempts to extract and showcase the first 10 images found on that particular webpage. ...

What steps are involved in creating a mobile web app using Visual Studio 2012, jQuery, and ASP.NET MVC?

As a beginner in asp.net, I am tasked with creating a mobile web app project. Before diving into development, I would like to first focus on designing my app. Can anyone provide guidance on how I can achieve this? Any help is appreciated. ...

The checkbox is displayed as selected after being clicked in conjunction with another checkbox

In the tree structure, there are checkboxes that behave strangely when clicked. I have already read a similar discussion here. The problem I am encountering is that when I click on an item, it gets checked but the console does not show it as checked immed ...

existing event handler in JavaScript has already been registered on a particular plugin

Apologies for the confusing title, will make changes accordingly.. Currently, I am utilizing the Twitter Bootstrap Wizard to manage database operations. My goal is to find a way to activate the onTabShow() function by simply clicking a button. The onTabSh ...

When the redirect page includes a parameter, it has the ability to conceal the functionality of the subsequent page

I'm looking to redirect my page to another page while also triggering a hidden function on the next page. When I click on the redirect link, I want the page to redirect and for the function on the next page to be called as well. <script type="text ...

Is there a way to make the text on my Bootstrap carousel come alive with animation effects?

My website features a Bootstrap Carousel with three elements structured like this: <a><img data-src="img" alt="Third slide" src="img"> </a> <div class="carousel-caption"> <h2> <u ...

How can I make my modal box appear after someone clicks on selecting a college?

Can someone help me figure out how to display my modal box after clicking into the selecting list? I've already coded it, but I'm struggling with getting it to show up after the click event. Any assistance is appreciated! In the image provided, ...

Ways to modify the final sum exclusively for a single table

I am currently struggling to figure out how to calculate only the grand total of the first table using just one jQuery/JavaScript script. The code I am referencing is from: Below is the code snippet: <!DOCTYPE html> <html xmlns="http://www.w3 ...