AnswerBun.com

How to change the order of jquery events?

Stack Overflow Asked by Turqay Umudzade on October 2, 2020

I have 2 events here one is click and one is focus on the input, I need the click to run before focus so I added a timeout to it but I feel like this isn’t an elegant solution.

  $(document).click(function(e) {
        var target = e.target;
        var lastElement = '#' + lastList;
        console.log('here first');
        if (!$(target).is(lastElement) && !$(target).parent().parent().is(lastElement) && !$(target).parent().parent().parent(lastElement).is(lastElement)) {
            $('.add-card .fa-plus').show();
            $(lastElement).children().children().children('textarea').addClass('pl-8 bg-gray-200');
            $(lastElement).children().children().children('textarea').removeClass('h-20 px-4 w-60 resize bg-white');
            $('.js-add-card-button').addClass('hidden')
        }
    });
    
    $(document).on('focus', '.js-create-card', function(e) {
        setTimeout(() => {
            console.log('here');
            $(this).siblings('.add-card .fa-plus').hide();
            $(this).removeClass('pl-8 bg-gray-200');
            $(this).addClass('h-20 px-4 w-60 resize bg-white');
            $(this).siblings('.js-add-card-button').removeClass('hidden');
            lastList = $(this).parent().parent().parent().attr('id');
        }, 100);
    });

So I have a few questions about the solution I used:

  1. Is there a async-await solution to this problem?
  2. The 100ms delay works for me but will it work on all PCs? Can a slower PC ruin this structure?

Add your own answers!

Related Questions

What will this recursive function yield?

1  Asked on December 9, 2021 by user13812739

     

How to style Rebass Switch

5  Asked on December 9, 2021 by amaster

       

Redis Cluster Mode – replicas not working

1  Asked on December 9, 2021 by ramprakash

     

Disable seeking in mediaelement.js

1  Asked on December 9, 2021 by pelirrojo

         

Table not getting created sqlite android

4  Asked on December 9, 2021 by user3844417

   

Angularjs using JWT breaks CORS to Amazon S3 on login

2  Asked on December 9, 2021 by codephobia

     

Write a value with opc ua Python

2  Asked on December 9, 2021

   

unable to install vue chart.js in vue

2  Asked on December 9, 2021 by prabina-sht

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP