FAQ accordion using HTML, CSS, JavaScript

Поділитися
Вставка
  • Опубліковано 13 гру 2024

КОМЕНТАРІ • 93

  • @TochiEmenine
    @TochiEmenine Рік тому +6

    A code that actually works, thank you. Really straightforward and short.

  • @salentipy
    @salentipy 7 місяців тому

    This is a wonderful video! I'm just learning JavaScript and watching it done line-by-line is EXTREMELY helpful! Thank you!

  • @iuseflare
    @iuseflare 4 місяці тому

    really straightfoward and readable code. thanks!

  • @АвтопилотКраснодар
    @АвтопилотКраснодар 10 місяців тому +9

    const faqs = document.querySelectorAll(".faq");
    faqs.forEach(faq => {
    const question = faq.querySelector(".question");
    const answer = faq.querySelector(".answer");
    question.addEventListener("click", () => {
    if (faq.classList.contains("active")) {
    faq.classList.remove("active");
    answer.style.maxHeight = null;
    } else {
    // закрытие других активных блоков
    faqs.forEach(otherFaq => {
    if (otherFaq.classList.contains("active")) {
    otherFaq.classList.remove("active");
    otherFaq.querySelector(".answer").style.maxHeight = null;
    }
    });
    faq.classList.add("active");
    answer.style.maxHeight = answer.scrollHeight + "px";
    }
    });
    });
    added hiding inactive blocks

  • @efekanefe442
    @efekanefe442 Рік тому +2

    Thanks for the max-height trick i was trying to send my answers upwards with translateY and negative margin top values :D Finally making accordion components with animations. Have a nice day

  • @mozcoder
    @mozcoder Рік тому

    Thank you for share this amazing video, you helped-me very much.

  • @jeanyvesarnold3519
    @jeanyvesarnold3519 9 днів тому

    Thanks you very much

  • @al4n250
    @al4n250 Рік тому

    Fantastic video. I will for sure use some of the tricks that you have used.

  • @tasneemayham974
    @tasneemayham974 Рік тому

    THANK YOU THAT WAS REALLLYY COOOLL!!!!!!!!!

  • @mudasarhussain2907
    @mudasarhussain2907 2 роки тому +1

    A.o.A!
    Ur effort is really helpful for us,thanks alot

  • @Dreamingofrainbows
    @Dreamingofrainbows Рік тому +2

    this tutorial was amazing, wow, I've learned so many new things and also new tricks about what I've used before, amazing! thank you, I'll be coming back for more tutorials!

  • @khasanboyerkinov
    @khasanboyerkinov 11 місяців тому +1

    thank you bro

  • @doneilchapman1542
    @doneilchapman1542 Рік тому

    Really nice tutorial

  • @jaspar797
    @jaspar797 Рік тому

    Great, thank you very much!!

  • @hadiqadimi9540
    @hadiqadimi9540 Рік тому

    very good thank you

  • @wetsand7379
    @wetsand7379 2 роки тому +1

    thank you, this was really simple to follow.

  • @okolipeace774
    @okolipeace774 Рік тому +1

    Thank you for this tutorial, it's really helpful and amazing.
    I learnt so much from it

  • @dhanalakshmip1645
    @dhanalakshmip1645 Рік тому

    Thakyou so so muchhhhhhh😍😍😍😍

  • @alexiscrespo1783
    @alexiscrespo1783 3 роки тому +1

    Nice video !!! Good job bro, thanks !

  • @londonching3343
    @londonching3343 2 роки тому

    Thank you bro, great video

  • @vivek5147
    @vivek5147 3 роки тому +17

    Plz source code

  • @swapnildhiman2032
    @swapnildhiman2032 2 роки тому

    Thanks it is really help full

  • @ayubitv03
    @ayubitv03 5 місяців тому

    Thank you bro..

  • @aimbotcz8033
    @aimbotcz8033 Рік тому

    thank you so much man😭

  • @xayrullayevzafar
    @xayrullayevzafar Рік тому

    Thank you very much!

  • @2kproductions1
    @2kproductions1 Рік тому

    thanks man👏👏

  • @nikolanidzeks
    @nikolanidzeks 2 роки тому

    Awesome job !

  • @catalinamarziali9786
    @catalinamarziali9786 2 роки тому

    Thank you very much! This tutorial was so helpful

  • @carlosz1858
    @carlosz1858 3 роки тому +2

    thanks bro, u helped me so much

  • @abdulwaarithkehinde955
    @abdulwaarithkehinde955 2 роки тому +2

    Really nice tutorial. Very simple to follow. Thanks a lot for this.

  • @IBRAHEMAL-KAMEL
    @IBRAHEMAL-KAMEL 6 місяців тому

    thank you so much

  • @mountmidia6780
    @mountmidia6780 Рік тому

    Thank you!

  • @adnan8465
    @adnan8465 2 роки тому +1

    thank you bro ,you have earned my respect

    • @sanadelayan688
      @sanadelayan688 2 роки тому

      Quick question was it responsive to you or not

  • @godmodeloss9345
    @godmodeloss9345 3 роки тому

    Thank you! You're help me! ;)

  • @shivanand0297
    @shivanand0297 2 роки тому

    nice

  • @iCanCombo.
    @iCanCombo. 3 місяці тому

    What do you use to autocomplete in css?

  • @atulcodex7730
    @atulcodex7730 2 роки тому

    Thank you :)

  • @GennyMilan-e6d
    @GennyMilan-e6d Рік тому

    thanks :)

  • @pawpawqwertyuiop
    @pawpawqwertyuiop Рік тому

    под музычку норм)

  • @sofaking6642
    @sofaking6642 3 роки тому

    good shiz

  • @lilyyeh8607
    @lilyyeh8607 3 роки тому

    thank you~~!

  • @sephyrion9207
    @sephyrion9207 2 роки тому +1

    @Developer Empire
    Thank you, all of it looks very good! Can you suggest a few excellent resources from where one could learn about SVG and advanced CSS? One of your lines there in CSS (line 65 I believe,) looks advanced to me, so I'd like to learn.

  • @alini9749
    @alini9749 2 роки тому

    thanks

  • @ob5804
    @ob5804 Рік тому

    What if height of ech content is different?? Could you make a video when we 2-3 accordions js??

  • @akidzul7748
    @akidzul7748 3 роки тому +3

    this helped so much, thank you! but can anyone explain why my arrow is only appearing half :( its like a half-v and looks more like a backslash for some reason. i think i followed the code closely but still couldnt determine what went wrong..would love to get some insight on this!

    • @Ditzj
      @Ditzj 2 роки тому +2

      I had the same. Depends on your background. I had a white background, and then the white SVG line obviously disappears and the only part remaining is the black fill of the triangle. You would need to set: stroke="black" (or any color you need) and fill="transparant" (in the path options) to get rid of the small black triangle. The way it was shown here, it will only look good on a black background.

    • @ezajhossain
      @ezajhossain 2 роки тому

      @@Ditzj thank you ❤️

    • @yskthegamer9033
      @yskthegamer9033 Рік тому

      @@Ditzj where exactly is "fill" ?

    • @Ditzj
      @Ditzj Рік тому

      @@yskthegamer9033 as an example:

  • @skillscrib6434
    @skillscrib6434 Рік тому +1

    Do you have a document where i can copy this code both Html and css

  • @Techno_2709
    @Techno_2709 Рік тому +2

    source code pls

  • @mudasarhussain2907
    @mudasarhussain2907 2 роки тому +1

    But 1thing which can't understand (where is "active,s class ")plz help me

    • @Ditzj
      @Ditzj 2 роки тому

      class=active get's set in the javascript when you click on the specific div-element

  • @lifeisbeautifu1
    @lifeisbeautifu1 2 роки тому

    Thank you

  • @ThisIsAbrarKhan
    @ThisIsAbrarKhan 3 роки тому

    How can we implement in blogger template

  • @Ludo045
    @Ludo045 2 роки тому +3

    i just dont fucking get it.. we have the same structure yet it doesnt work in my project..

    • @andressmendess
      @andressmendess 2 роки тому

      me either, did you get it?

    • @yeyintaung9839
      @yeyintaung9839 2 роки тому

      @@andressmendess I don't get it either. I copied the exact same thing and it still isn't working

  • @MarcusStevens-v9m
    @MarcusStevens-v9m 2 місяці тому

    Jerde Hollow

  • @BrendaMartinez-o9z
    @BrendaMartinez-o9z 2 місяці тому

    Jerad Forge

  • @jewelofnile2424
    @jewelofnile2424 2 роки тому

    Why do You set max 300? How do You know how much text everyone uses? For me it's bad example of accordion because it's not for future projects where you could have more text.

    • @adziak
      @adziak Рік тому

      set max to fit-content

  • @maridurai6178
    @maridurai6178 7 місяців тому

    What this design name

  • @cotnegviniashvili5019
    @cotnegviniashvili5019 2 роки тому +1

    can u give source cod?

  • @saidibra9231
    @saidibra9231 2 роки тому +1

    when you click on another one is not closing ,?

    • @adnan8465
      @adnan8465 2 роки тому +2

      you are right, other remains open

    • @Ditzj
      @Ditzj 2 роки тому

      It would have to look like this:
      faq.addEventListener("click", () => {
      if(!faq.classList.contains("active")){
      faqs.forEach(faq => {
      faq.classList.remove('active');
      })}
      faq.classList.toggle("active");
      });
      So check if the current clicked on FAQ is already active. If not, then remove the active class from all items, otherwise just toggle the active state.

    • @saidibra9231
      @saidibra9231 2 роки тому

      @@Ditzj thank you

  • @alexandrarudman1478
    @alexandrarudman1478 Рік тому

    Alguien puede decirme los códigos para que abra solo 1 respuesta, al darle clic que se oculte la anterior.????

  • @vanshkhera206
    @vanshkhera206 3 роки тому

    is it responsive??

  • @KallieLoggins-o4w
    @KallieLoggins-o4w 2 місяці тому

    Enid Fork

  • @lolerkapich
    @lolerkapich Рік тому

    gj

  • @bennisa8102
    @bennisa8102 Рік тому

    Mine has more space between the title and the paragraph regardless of what margin or padding I try to use. Can someone help? The code is the same. Trust me. I've checked.

  • @angelablanca7456
    @angelablanca7456 2 роки тому

    Thank Youuuu

  • @ferni777
    @ferni777 2 роки тому

    can you please upload the source code?

  • @shardulpandey3
    @shardulpandey3 6 місяців тому

    svg is not showing

  • @kickdoe6793
    @kickdoe6793 2 роки тому +1

    The solution is not bad, but if you do not know the final maximum height, then difficulties arise here, if you specify the maximum height in auto, then the animation stops working, I still have not found solutions to this issue, if someone has a solution, please share

    • @hedikharouf297
      @hedikharouf297 Рік тому +1

      You can set the max-height to fit-content ( .faq.active .answer{max-height: fit-content;}

    • @kickdoe6793
      @kickdoe6793 Рік тому

      @@hedikharouf297 When you specify this property, the animation stops working.

    • @zxero69
      @zxero69 Рік тому

      I know I'm late, but if you want to do it without set max-height then u should put transform translateY(-100%) instead, and overflow hidden. Then for active class just bring back translate to 0

  • @HussnainHussnain-tu8ny
    @HussnainHussnain-tu8ny Рік тому

    send me code
    html css js

  • @syediqbalahmed3176
    @syediqbalahmed3176 3 роки тому

    vulu ... ocay ...

  • @ryanjasperavendano2994
    @ryanjasperavendano2994 Рік тому

    souce code :>>

  • @Duckergg.j
    @Duckergg.j Рік тому

    It doesn't work 👎

  • @MusicRachael136
    @MusicRachael136 3 роки тому +5

    not a good tutorial!

  • @gayathri-8-i6s
    @gayathri-8-i6s 4 місяці тому

    source code plz