Event Delegation in Javascript | UI/Frontend Interview Question

Sdílet
Vložit
  • čas přidán 20. 02. 2019
  • - What is Event Delegation?
    - A quick demo and examples of this techniques
    - Benefits of Event Delegation?
    - Limitations of Event Delegation?
    Link to code of Example 1 - codepen.io/akshaymarch7/pen/M...
    Link to code of Example 2 - codepen.io/akshaymarch7/pen/o...
    If you get to learn something from this video then do give it a thumbs up and subscribe to my channel for more such videos.
    If you want me to cover any specific topic, then comment down below. I would be happy to help you.
    If you find my videos helpful,
    then please support this channel by buying a coffee,
    www.buymeacoffee.com/akshayma...
    Cheers,
    Akshay Saini
    akshaysaini.in
    Would love to Stay Connected with you ❤️
    LinkedIn - / akshaymarch7
    Instagram - / akshaymarch7
    Twitter - / akshaymarch7
    Facebook - / akshaymarch7
    #Javascript #JavascriptInterviewQuestions #AkshaySaini

Komentáře • 156

  • @Abhishek-dp5tc
    @Abhishek-dp5tc Před 2 lety +84

    Benefits of event delegation:
    1) improves memory space
    2) mitigates risk of performance bottle neck
    3) Dom manipulation
    4) when elements get added dynamically, the process of adding events is slow
    Limitations:
    1) All the events are not bubbled up, some events like blur, focus are not bubbled up
    2) if e.stopPropogation is used in child, then events are not bubbled up

  • @cnsnmms3708
    @cnsnmms3708 Před 3 lety +53

    Eventually found someone who really knows something and shares it on youtube :D

  • @shadestorm3995
    @shadestorm3995 Před 3 lety +31

    I have been adding listeners on loop like an idiot when I could have just done this...
    This was enlightening to a great degree.

    • @mridulkumar4087
      @mridulkumar4087 Před 2 lety +3

      Your are even adding a loop but I have been adding a event listener each and every time for every element

    • @jamesonvincent3779
      @jamesonvincent3779 Před 2 lety

      i know im randomly asking but does someone know of a trick to log back into an instagram account?
      I stupidly forgot my password. I would appreciate any tricks you can give me!

  • @BaishaliGhosh13
    @BaishaliGhosh13 Před 4 lety +11

    I have been terrified of frontend questions in fullstack positions but your videos have given me so much clarity and insight into the working of JS. Thanks a lot Akshay.

  • @user-uh3zr7mo4i
    @user-uh3zr7mo4i Před 4 lety +10

    Dude! I love you . These videos are really helpful for self taught devs.

  • @saritajha1
    @saritajha1 Před 2 lety +4

    You are absolutely right !! it opened my eyes when I actually understood this concept :)
    No tutorial/ video ever explained delegation this way. Can't thank more Akshay.
    God bless you.

  • @onlynaveen
    @onlynaveen Před 4 lety +2

    Hi sir, after 1 year learning you lesson me a practical and real things, Thanks for advise and teach.

  • @hardikluhar4738
    @hardikluhar4738 Před 2 lety +3

    These videos are really helpful for self-taught devs.

  • @subhamshaw1726
    @subhamshaw1726 Před 2 lety

    after namaste javascript, this frontend interview question playlist had helped me a lot. I can apply this things in my work as well as ace my interviews.
    All thanks to YOU, sir

  • @ryansantiago3684
    @ryansantiago3684 Před rokem +1

    No joke, you are the best person when it comes to explaining. I really recommend you Akshay! Keep it up!

  • @rameshbankuru421
    @rameshbankuru421 Před 4 lety +8

    Akshay Saini, Dude! I love you. These videos are really helpful for me

  • @sowmithreddy18
    @sowmithreddy18 Před 3 lety +15

    Never knew data attributes could be used this way. Amazing !

  • @shishirsonekar5661
    @shishirsonekar5661 Před 4 lety +5

    Thanks, Akshay for this perfect explanation...
    Also,
    Being a full-stack developer and like me, a lot many FS devs keep ignoring CSS because it needs a proper understanding of not just the target element as well as the effects passed on from parents in the hierarchy. Overall, CSS being a secondary skill for this reason as well, it's not focused much in tech Interviews. But, I feel it is much-required skills to deliver a quality products. If you've cracked CSS properties' relations with its parents in the hierarchy, I'm sure huge junta including me would like to learn it from you!...

  • @SAIRAM-ct5cy
    @SAIRAM-ct5cy Před 3 lety +1

    Good job Akshay..its amazing how you present the concepts precisely.Keep up the good work!!

  • @chamnil8666
    @chamnil8666 Před 3 lety

    Thank you for making these free videos.They are so educational.keep up the good work.

  • @ishusharma415
    @ishusharma415 Před 2 lety

    Really useful information and very well explained lectures. One of the best channel to prepare for front end interviews. Thank you so much for creating this channel.

  • @samdatta9163
    @samdatta9163 Před 4 lety +1

    Good Quality and informative video.I kept all the concepts in my mind for interview.Thanks so much.

  • @gyanendraverma3155
    @gyanendraverma3155 Před 3 lety

    best javascript knowledge. I was looking at this kind of depth of knowledge in javascript.

  • @codingwithgraceandtruth2456

    hooked to your tutorials, really good quality in teaching and content.

  • @lovishgoel2745
    @lovishgoel2745 Před 3 lety +1

    best series so far

  • @priyaranjan1733
    @priyaranjan1733 Před 5 lety +1

    In CSS, we use as event delegation mean, we assign our base tag's href for all tags in that page. This is just analogy for those who know but not Event Delegation. 😕

  • @PeaceUrSoul
    @PeaceUrSoul Před 4 lety +1

    Hi Akshay, thanks for bringing such insights logics. Keep post such videos..

  • @charanckck
    @charanckck Před 2 lety

    Love you man. Thanks for your time and knowledge.

  • @md.mohiulislam6516
    @md.mohiulislam6516 Před rokem

    This guy is awesome. Love from Bangladesh.

  • @VinayVerma22
    @VinayVerma22 Před 5 lety +1

    Very nice and precise tutorial with great examples. Requesting you to make a video on "Event Loop". :)

  • @prabu2778
    @prabu2778 Před 3 lety +1

    You are great !!!!!!?
    Helping so many poor people

  • @mohann7750
    @mohann7750 Před 3 lety

    Thanks Dude..Helped me to learn events in javascript in depth..

  • @gokulsrinivasan8563
    @gokulsrinivasan8563 Před 2 lety

    Akshay,Thank you so much these videos. You explanation is pretty clear. Thanks again.

  • @shivGGG
    @shivGGG Před 3 lety +1

    Amazing stuff, great way of teaching :)

  • @ShouvikMitraPlus
    @ShouvikMitraPlus Před 5 lety +35

    Nice one! also got to know how frameworks make use of custom attributes like data-dismiss="modal" in bootstrap. Thanks!

    • @akshaymarch7
      @akshaymarch7  Před 5 lety +51

      You're absolutely right Souvik and the people who write frameworks are just like us, it's just that they understand these core concepts very well and how things work under the hood. Keep on learning these basic concepts and slowly everything will make sense and you will get a lot more wow moments. :)

    • @Abhishek-do8mp
      @Abhishek-do8mp Před 2 lety +1

      @@akshaymarch7 ab to aajao sir

  • @snehashischattopadhyay9519

    bro learning a lot from your videos. Please please please upload more videos on Javascript. Also if possible discuss on tricky CSS, HTML questions.

  • @iqrarhussain7136
    @iqrarhussain7136 Před 21 dnem

    Very beautiful concept, and beautifully taught by Akshay sir.

  • @vandanachintala8326
    @vandanachintala8326 Před 4 lety +2

    Thanks Akshay for awesome explanation of each topic. I have gone through your event bubbling and capturing video before this one. I think your first example regarding categories is the best example of enabling event capturing. Since we are attaching event handlers to parent - instead of events bubbling from child to parent, we can enable useCapture property and can stop delegation to child elements for better performance using e.stopPropagation().

    • @kirankamath5891
      @kirankamath5891 Před 3 lety

      but how we will understand from where the event actually occurred if the target is the child element

  • @priyankachhabria6769
    @priyankachhabria6769 Před 2 lety

    This was amazing. Thanks for making it so simple.

  • @Siddarthathota
    @Siddarthathota Před 5 lety +1

    Awesome explanation man.. kudos

  • @utpalclicks
    @utpalclicks Před 4 lety +10

    And for the last example, we can merge it with "denounce" so that the event only triggers once the user stop typing... 😀
    You explained this very well... Thanks!!

    • @aadispare3673
      @aadispare3673 Před rokem +1

      Nope. Debounce on input field validation is a very bad idea.
      You need to notify the user as soon as he types something against the rules, instead of letting him know after he's finished typing a long sequence of mistakes. That is bad user experience.

  • @shoaib_akhtar_1729
    @shoaib_akhtar_1729 Před 17 dny

    Hats off, awesome teaching skills.

  • @navdeepsr93
    @navdeepsr93 Před 4 lety +1

    Thanks Akshay , you explained very nicely . :)

  • @himanshushekhar3694
    @himanshushekhar3694 Před 3 lety

    such a nice video with great explaination...Thank you so much

  • @TanayBhalani
    @TanayBhalani Před 3 lety

    Amazing video, learnt a lot✌️ thank you Akshay 👍

  • @DharmendraKumar-qk5bt
    @DharmendraKumar-qk5bt Před 5 lety +1

    It's awesome. Thanks

  • @dinesh9896
    @dinesh9896 Před 11 měsíci

    thank you brother for making it very clear!

  • @musicsubhankar
    @musicsubhankar Před 3 lety

    This was nicely explained. Keep up the good work. :)

  • @profjs2398
    @profjs2398 Před 2 lety

    excellent video, thank you Akshay

  • @iaindudman3349
    @iaindudman3349 Před 2 lety

    Excellent examples and explinations👍

  • @tusharkrishna8149
    @tusharkrishna8149 Před 4 lety +1

    Your explanation is too good, can you make a video on java script timers please

  • @suthagarthambikannu6402

    nice video and simple understandable English. Very useful for me

  • @anandyadav_
    @anandyadav_ Před 3 lety

    older videos are one level good than newer ones😋

  • @mohitkushwaha8156
    @mohitkushwaha8156 Před 2 lety

    Video is very helpful
    grateful to you

  • @dhrumit7
    @dhrumit7 Před 2 lety

    @Akshay Saini
    Your videos are very insightful. Please do one video on Infinite Scroll and Pagination.

  • @MrMaulikthaker
    @MrMaulikthaker Před 3 lety

    second example when you type anything then that much time function is called. So I think its the case of function re-calling wihile each character we typed in event delegation.

  • @sagarkumar4816
    @sagarkumar4816 Před 3 lety

    awesome video .. very informative .. please make more videos

  • @SauravKhare
    @SauravKhare Před 3 měsíci

    Really useful examples.

  • @velmurugan-jo3vb
    @velmurugan-jo3vb Před 5 lety

    Awsome Akshay..... Make video on "Event Loop"

  • @namankeshari7332
    @namankeshari7332 Před 10 měsíci

    Awesome video once again!

  • @videosforinventionimaginat2410

    Sir very nice , video very simple, clear and directly getting into our head
    Sir also make real time video of securing API , and make webpage loading g faster in UI

  • @TheRichEng
    @TheRichEng Před 5 lety +1

    Awesome brother

  • @sandeepadiyar001
    @sandeepadiyar001 Před 4 lety

    Thanks very much akshay. Yours videos are very helpful and quite descriptive and understandable. Can you please make one video on webpage security. I mean from a frontend developer point of view how can I add security to a web app. Thanks in advance

  • @karensanchez7308
    @karensanchez7308 Před 4 lety

    Superb, thanks.

  • @kalyanparri8517
    @kalyanparri8517 Před 3 lety

    Thanks for information sharing

  • @samadhansalgar9181
    @samadhansalgar9181 Před 3 lety

    !! Its so easy to learn from your @video Thanks lot for such great video !!! ,
    Please cover one fronted template with javscript, Jquery if possible with AJAX, animation
    or only with Javascript with animation

  • @jayanthbondi4251
    @jayanthbondi4251 Před 2 lety

    Wonderful explanation !!

  • @techbjunks
    @techbjunks Před 5 lety +1

    we can also do event delegation with capturing phase.

  • @creativemind4116
    @creativemind4116 Před 2 lety

    Thanks for your valuable explaination.
    now i'm bit confuse between event bubbling and event deligation.

  • @sumonbarai178
    @sumonbarai178 Před rokem

    thanks for totorial.....

  • @pritamchowdhury4191
    @pritamchowdhury4191 Před 4 lety +1

    It was just fantastic.Thank you so much brother

    • @pritamchowdhury4191
      @pritamchowdhury4191 Před 4 lety

      can u make a video about how javascript engine works.thanks in advance

  • @AbhishekGupta-bg8wt
    @AbhishekGupta-bg8wt Před 4 lety

    please make more videos on these type of things

  • @12vvs
    @12vvs Před 4 lety +1

    Great!

  • @Priyanka_12321
    @Priyanka_12321 Před 5 měsíci

    Thank you so much sir 😀🙏

  • @AdnanAli-cp9hk
    @AdnanAli-cp9hk Před měsícem

    amazing amazing amazing!!!!

  • @MujahidAli-gi6jk
    @MujahidAli-gi6jk Před 2 lety

    I just only sy kitna awesome parhata ha yar

  • @anonymousshooter3636
    @anonymousshooter3636 Před 3 lety

    Very Informational

  • @SHIVAMPANDEYSJTG
    @SHIVAMPANDEYSJTG Před 2 lety

    You are awesome!

  • @valurathod8579
    @valurathod8579 Před 4 lety

    Dude your videos are awesome and useful.. Can you please make video on angular?

  • @bahaakrayem4104
    @bahaakrayem4104 Před 5 lety +1

    Great

  • @MunshiWahid
    @MunshiWahid Před 3 lety

    This video should get more likes

  • @surabhipal9553
    @surabhipal9553 Před 3 lety

    Thank you

  • @kiranmahajan778
    @kiranmahajan778 Před 3 měsíci

    In event delegation we would have to write a lot of if and else condition to handle different click events

  • @vitalvisions4U
    @vitalvisions4U Před 3 lety

    Got this too.

  • @jayanthbabusomineni557
    @jayanthbabusomineni557 Před 5 lety +1

    Please make video on closures in JavaScript

  • @aburaihan-py4vi
    @aburaihan-py4vi Před 2 lety

    Excellent!

  • @somhrikkonar6147
    @somhrikkonar6147 Před 2 lety

    Thanks

  • @techguybiswa
    @techguybiswa Před 5 lety +1

    WOW So cool! Awesome explanations!

  • @shubamdadhwal3497
    @shubamdadhwal3497 Před 2 lety

    Excellent Explanation Akshay, I have a minor doubt - as you have said it we can only do event delegation because of event bubbling, but while playing with the code, when i set the useCapture flag to true, it was working perfectly fine too, can you explain this behaviour?

  • @hundredeyes7759
    @hundredeyes7759 Před 5 lety +3

    Finally I got it!!. is this the same way how react-router work? i mean like not exactly the same but core concepts are this only right?

    • @akshaymarch7
      @akshaymarch7  Před 5 lety +1

      I don't know exactly about it. React router is all together a giant concept, won't be this simple. But yeah this concept is often used for setting behaviour patters in the code :)

  • @simranbhatia2402
    @simranbhatia2402 Před 2 lety

    Superb

  • @diwakardayal954
    @diwakardayal954 Před 4 měsíci

    thanks

  • @senaitmekonnen692
    @senaitmekonnen692 Před 2 lety

    thankyou

  • @abhilayman8533
    @abhilayman8533 Před 4 lety

    document.getElementById is faster than document.queryselector , so use the first one.

  • @sahilsatishkumar
    @sahilsatishkumar Před 4 lety +1

    So I am not the only person who is reminded of the time by them machines

  • @AnasShahidIqbal
    @AnasShahidIqbal Před 2 lety

    So in the frameworks like angular where we can loop through the list and attach an event listner on each item does attach a separate event for it or it takes care of delegation internally?

  • @Rajavinoth1981
    @Rajavinoth1981 Před 4 lety +1

    Super

  • @tarunchanderbhatt
    @tarunchanderbhatt Před 4 lety

    great

  • @ashwanipayal8658
    @ashwanipayal8658 Před 3 lety

    Nice!

  • @larrysmusics531
    @larrysmusics531 Před 3 lety

    Perfect

  • @prakhar992
    @prakhar992 Před 4 lety

    Hi.
    Can you make video on accessing elements in a shadow root?

  • @sunilthind3257
    @sunilthind3257 Před 2 lety

    @akshay
    Can you please show in a video how can we achieve event delegation in react components

  • @RavindraSingh-zg9eq
    @RavindraSingh-zg9eq Před rokem

    nice

  • @manojkumarsaheng
    @manojkumarsaheng Před rokem

    Thx more knowledge video but Request video Virtual DOM and Actual DOM