How to create an Accordion using CSS & Javascript

Поділитися
Вставка
  • Опубліковано 9 вер 2024
  • Enroll My Course : Next Level CSS Animation and Hover Effects
    www.udemy.com/...
    Another Course : Build Complete Real World Responsive Websites from Scratch
    www.udemy.com/...
    ------------------
    Join Our Channel Membership And Get Source Code of My New Video's Everyday!
    Join : / @onlinetutorialsyt
    ------------------
    Patreon : / onlinetutorials
    Facebook Page : / onlinetutorialsyt
    Instagram : / onlinetutorials_youtube
    Twitter : / onlinetutoria16
    Website : www.onlinetutor...
    Buy Me A Coffee : www.buymeacoff...
    ------------------
    give proper credit if you repost this on other social media platform
    ------------------
    Disclaimer video is for educational purpose only. Copyright Disclaimer Under Section 107 of the Copyright Act 1976, allowance is made for "fair use" for purposes such as criticism, comment, news reporting, teaching, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational or personal use tips the balance in favor of fair use

КОМЕНТАРІ • 147

  • @lernist.oficial
    @lernist.oficial 3 роки тому +13

    I have been watching tutorials for a week, now, at 3am, your video has finally made me finished the final step of my project, thanks a lot man, keep it up

  • @sfrstatus9070
    @sfrstatus9070 4 роки тому +14

    Guys an easier method:
    Heading
    Lorem
    Then style it

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

      wow so simple :O

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

      Then how will you learn Javascript?

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

      @@sulaimandev the people who are making projects should learn Javascript first and then come here

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

      Do you mean it takes fewer DIV ?

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

      how do you add transitions to this?

  • @anasyoussi514
    @anasyoussi514 3 роки тому +7

    Using ForEach :
    const accordion = document.querySelectorAll('.contentBx') ;
    accordion.forEach(acc => {
    acc.addEventListener('click', function(){
    this.classList.toggle('active');
    })
    })

  • @kieran2347
    @kieran2347 4 роки тому +5

    This is amazing. thanks for this video especially for keeping them short and to the point and ofcourse covering all the parts

  • @yvesyao3529
    @yvesyao3529 4 роки тому +4

    You are reading my mind teacher, I was trying to do that too. too loud, thank you teacher

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

    thanks bro... I got sucked up here from the last hour and helped me..

  • @eder.santana_oficial
    @eder.santana_oficial 4 роки тому +9

    Eu já entro dando like, seus vídeos são bons de mais

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

      KKKK, aposto que ele deve tá entendendo tudo

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

    Thank yout so much, I made the code in another way but I used yout logic and now my web project is neer to be finished :D, muchas gracias hermano.

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

    Wow this was so easy and clear , I didn't expect that 😂

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

    Thank you so much for this. Please is there a way to remove the scroll bar, because mine is showing like a dot even when the tab is closed, so the user is able to scroll when the tab is closed from that dot scroll bar... is there a way to remove the scroll bar entirely?

  • @rayjenscode3501
    @rayjenscode3501 3 роки тому +4

    nice tutorial. Did you try height 100%? It seems the animation won't effect.

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

    Coding & Piano, best match of all!

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

    mazaa agya

  • @tadakuniyasuda8214
    @tadakuniyasuda8214 4 роки тому

    AMAZING!!!!!!!!!!!!!!!!!!!!!!!!!! Thank you . you are my hero.

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

    super very use full title thank you

  • @roger6388
    @roger6388 4 роки тому

    Wow you are the best I have learned many styles of css because of you.Thanks alot 😃 😊

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

    Thank you, great and simple tutorial.

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

    Great tutorial man, that really helped

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

    Very concise. Thanks so much this was really helpful.

  • @snssatyabhagavan
    @snssatyabhagavan 4 роки тому +1

    I set alarm to see the video first but failed 😁
    Nice

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

    Great tutorial, to the point and it works...thank you..

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

    Thank you for this tutorial.

  • @AnujGupta-kw9sw
    @AnujGupta-kw9sw 4 роки тому

    Easiest than I've ever seen

  • @chandrakanthpadi
    @chandrakanthpadi 4 роки тому

    You are doing an awesome work.

  • @ahangaraadil
    @ahangaraadil 4 роки тому

    That is totally sick. 👨‍💻

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

    thanks, i was in need of that.
    Gratitude

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

    Amazing video! very helpful, Thanks

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

    Very nice Teacher

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

    thanks

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

    Amazing work! Thanks for sharing.

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

    This is very helpfull for me.

  • @soft-coding
    @soft-coding 4 роки тому +1

    Thanks!!

  • @seenuiropias553
    @seenuiropias553 4 роки тому

    Thank you. Very useful.

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

    Good Video !

  • @doyelbhattacharjee3592
    @doyelbhattacharjee3592 4 роки тому

    Thank for making this🙏🙏

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

    Very cool. Easy JS

  • @GuilhermeSilva-ex1qk
    @GuilhermeSilva-ex1qk 4 роки тому

    AWESOMEEEEE! VERY VERY GOOD BRO!

  • @maskman4821
    @maskman4821 4 роки тому +1

    This is vey useful, accordion seems play an important role in ui/ux, it is cool to have such an ui element in web page !!!

  • @shassan7
    @shassan7 11 місяців тому

    height of conent should be changable due to text

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

    hey did anyone have any issues with their code? My toggle class doesn't work, everything seems to be fine with the code, but toggle isn't enabled. Any recomms?

  • @Yogibaba_youtubewala
    @Yogibaba_youtubewala 4 роки тому

    Awesome as usual

  • @hanutsai6860
    @hanutsai6860 4 роки тому +1

    very good

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

    Awesome, thanks...

  • @vietnguyenZ2
    @vietnguyenZ2 4 роки тому +2

    It's nice but not dinamic. Because you fixed height when collapse. Scroll appear when content so long. I want more...

    • @OnlineTutorialsYT
      @OnlineTutorialsYT  4 роки тому +1

      Add Overflow-Y: auto; in .contntBx

    • @vietnguyenZ2
      @vietnguyenZ2 4 роки тому +1

      ​@@OnlineTutorialsYT I agree about scroll. But more case, content maybe short or long height, fixed height 150px is not perfect. Not same bootstrap collapse with all case

  • @surenderoati
    @surenderoati 4 роки тому

    just awesome 🥰🥰

  • @chemedev
    @chemedev 4 роки тому

    Impecable!

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

    You should be using event delegation.

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

    Very niceee man s2s2s2 thank you very much

  • @NejdetACAR
    @NejdetACAR 4 роки тому +11

    I think there's a logic error (in my opinion) in the code running
    After the content box is opened, it should only close when the content title is clicked, but it also closes when the content text is clicked.
    In other words, I want the opening and closing operations to be done only when the content title is clicked. I think this is what makes sense.
    How can I fix this problem.

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

      It actually becomes convenient when a reader clicks a larger area to close it. No need to be precise. Do you agree?

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

      @@HongKong1842 no, because I for example need the user to use inputs and buttons in the content part. How are they gonna use anything if as soon as they click the content disappears?

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

      You can achieve that like this.
      - Give the text tag a class name.
      - in eventListener function
      function(e) {
      if(e.target.closest("class_name_of_the_text_tag")) return;
      this.classList.toggle("active");
      };

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

      @@brangja4815 can you elaborate on this I tried what you said but it still doesnt work.

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

      @@brangja4815 there is a better and easier solution.. by my opinion:
      const accordion = document.getElementsByClassName("content-box");
      for(let i = 0; i < accordion.length; i++){
      accordion[i].firstElementChild.addEventListener("click", function() {
      accordion[i].classList.toggle("active");
      })
      }
      the firstElementChild will get the element ();
      obviously if you wounld insert other child elements first, you should change this property with children[nth]
      ...accordion[i].children[2].addEventListener("click", function() ....
      @kokonut5498

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

    Nice

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

    thanks a lot sir

  • @cyrusgracias4556
    @cyrusgracias4556 4 роки тому +4

    We can build accordion using HTML details and summary elements easily

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

      how do you add transitions to them, transitions seem not to take effect

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

    getting bugs on this with iOS/safari - namely issues toggling the active class. Are there known fixes for iOS/Safari?

  • @renukagargicollege1486
    @renukagargicollege1486 4 роки тому +1

    nice video

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

    Very nice!!!!

  • @soullessleftover8427
    @soullessleftover8427 4 роки тому

    Say any chance of making a grid like Xiaomi's website for products? Looks really minimalistic and is very polished.

  • @boyemarc-antoine7027
    @boyemarc-antoine7027 2 роки тому +1

    if u dont put a fixed haight value, animation dont work.

  • @tanishbhamare3365
    @tanishbhamare3365 4 роки тому

    Awesome!👍👍

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

    thanks for this

  • @akview6460
    @akview6460 4 роки тому

    can you make some different nav bar which seems classic and beautiful

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

    amazing

  • @Mieystery
    @Mieystery 9 місяців тому

    Can i make it already opened?

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

    thanks. cool

  • @MuthuKumar-qx2ne
    @MuthuKumar-qx2ne 3 роки тому

    Super

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

    Can you create a tutorial -- when open a tab then automatically close the open tab

  • @mr.guardian4491
    @mr.guardian4491 4 роки тому +1

    Sir, how you learn these advanced things? Please tell me

  • @prasaddhend5500
    @prasaddhend5500 4 роки тому +1

    Brother when we click on one box another box *automatically* closed.
    Like - when we click on 1st box
    2,3,4 boxes close *automatically*
    When we click on 3rd box
    1,2,4 boxes *automatically*.

  • @CNUVAS0236
    @CNUVAS0236 4 роки тому

    can u design thumbnail slider/carousel with icons(forward & backward) on top on either right or left?

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

    A few others have mentioned this. I lose the transition animation when I try to set the active height to 100%, fit-content, or auto. Any solutions? It would be more responsive if the height was dynamic.

    • @janemig
      @janemig 19 днів тому

      Was there an answer to this? I am having the same issue.

    • @ericdimarzio5756
      @ericdimarzio5756 19 днів тому

      @@janemig Kevin Powell has some new videos on recently added css animations for display none and display auto. Check his channel out.

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

    Why toggle is not working for me, I did everything in this tutorial

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

    what's the use of position:relative in your code? It's everywhere.

  • @AnjuGupta-jy6lj
    @AnjuGupta-jy6lj 3 роки тому

    Which text editor you are using ?

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

    How to creat a rotate effect icon on ckick?

  • @wtfmomentninenine
    @wtfmomentninenine 4 роки тому

    Iam from Indonesia 🇮🇩

  • @donny533
    @donny533 4 роки тому +1

    awesome! is there a way to make the effects horizontal instead of vertical?

  • @BWVidventures
    @BWVidventures 10 місяців тому

    sir do u have a source code uploaded?

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

    1:24 `body { display: flex; ` why?

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

    can anyone please explain to me why the "active" class was added before the content. i didn't get the logic. I'm new so it would mean a lot if someone clears this doubt. i don't even know the name of the concept so I cant search the web for it.

  • @AJKING-tq3pd
    @AJKING-tq3pd 4 роки тому

    Sir please show how to make a calculater with the input from keyboard. I really worked hard but I didn't successed.

  • @user-wx5td9tw2h
    @user-wx5td9tw2h 4 роки тому

    Hi! How make accordion in the accordion? Say me please.

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

    hey!!
    my CSS are not reflecting??😮‍💨😮‍💨 help plsssss

  • @Nehayadav-nh5zy
    @Nehayadav-nh5zy 2 роки тому

    Hey I am unable to see the active tab

  • @twitchplus3593
    @twitchplus3593 4 роки тому

    Awesome

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

    I want to close the first row if I clicked the second row. How can I do that?

  • @roshansajeev4855
    @roshansajeev4855 4 роки тому

    Hi onlinetut do you have a discord channel

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

    This is okay but if you click the body content it will be closed automatically, nice for viewing information but not in transactional HTML users

  • @kumarianshu-zl6jo
    @kumarianshu-zl6jo Рік тому

    heii my active is not working

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

    send me code 🖥🖥 , Please 🙏🙏

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

    i fell asleep and its 6 oclock now

  • @lefamofokeng8291
    @lefamofokeng8291 11 місяців тому

    Source code??

  • @Venistro
    @Venistro 4 роки тому +1

    Why with JavaScript and not CSS/HTML only?

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

      Would it become easier or harder? This version is quite simple enough to me already.

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

      @@HongKong1842 I would say simpler. But I would prefer CSS only, cause it still works when someone disable/blocks Javascript. Sometimes maybe because a self created adblocker filter blocks to much and such things.

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

      @@Venistro u mean js is simpler.

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

      @@HongKong1842 CSS only is simpler in my opinion. It uses only checkboxes and css selectors.

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

      @@Venistro perhaps you write and share a version for us to compare.

  • @ultimategaming517
    @ultimategaming517 4 роки тому +1

    you are legend buddy plez plez plez give me your no. i will not disturb you

  • @ahmadbinabaskpm-guru6532
    @ahmadbinabaskpm-guru6532 Рік тому

    SIR CAN SHARE THE CODING

  • @ahmed-4065
    @ahmed-4065 2 роки тому

    it doesn't work :(

  • @mdmanik-xy7ui
    @mdmanik-xy7ui 3 роки тому

    I can make it bootstrap very easily

  • @f.o.x.x.2.0
    @f.o.x.x.2.0 3 роки тому

    else height content > 150px ?)

  • @peshotod
    @peshotod 4 роки тому

    somehow the script doesn't work

  • @aaaaaadhxhdh
    @aaaaaadhxhdh 9 місяців тому

    didnt work

  • @learnelectronics5322
    @learnelectronics5322 4 роки тому +4

    If you ask me what is the most difficult achievement in life..
    Ans.. Getting a ❤️ from Online tutorials..(the genius)..
    { I never get that msg in my yt notifications } 😂😂..

    • @FUNNYVIDEOS-tt7po
      @FUNNYVIDEOS-tt7po 4 роки тому +1

      Wow you told him about your wish and he fulfilled it.. I think he's a God who fulfills wishes
      ( His creativity shows his talent)

  • @369vkr
    @369vkr 3 роки тому

    Hi where is da sos fil