JavaScript DOM Tutorial #17 - Tabbed Content

Поділитися
Вставка
  • Опубліковано 2 лют 2025

КОМЕНТАРІ • 50

  • @coverdrive25
    @coverdrive25 6 років тому +33

    For those using the Css of the earlier files, this may not work. Just change .tab to .panel i your Css file.

    • @noobiexd640
      @noobiexd640 5 років тому +1

      Thanks for your info man!

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

      I couldn't figure how to fix this problem. Can you help?

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

      i read the whole code 3 times to check the error then came to comments
      it worked out for me thanks

  • @BigSmoke-r9w
    @BigSmoke-r9w 11 місяців тому

    i love this! Thank you net ninja! You are truly the programming sensei that we need

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

      I appreciate that! :) thanks so much for watching

  • @javabeanz8549
    @javabeanz8549 6 років тому +2

    I want to say THANKS! for this video, it fit right into the project that I was working on, the other Tab methods I checked out really didn't fit in with the rest of the project.

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

    Hey, thank for this all, you are the best, i really love your tutorials, i even cannot express my respect to you, I'm really grateful, thank you, thank you bro
    Yours sincerely
    Little Ninja

  • @zuber3228
    @zuber3228 6 років тому +1

    tanks a lot to make this video , you know i was crazzy to learn this thing , i try my level best to find it everywhere but i did't get, one day i visited you'r youtube channel , there i found , now i am so happy that i know this , and i got this

  • @Abaramotorai
    @Abaramotorai 6 років тому +3

    Holy Cow! You are the best! Thank you.

  • @boboboboboboo7522
    @boboboboboboo7522 6 років тому +8

    curious why doesnt it work if the conditional e.target.tagName == 'li';
    why does it have to be upper case? i confused
    EDIT: had something to do with taglist being returned in caps meh -.-

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

    Best so far...

  • @MrCritterJohn
    @MrCritterJohn 6 років тому +7

    How does the if(panel == targetPanel) comparison work? I understand that targetPanel contains either #about or # contact, but what is the value of panel? Do we just infer that panel contains either #about or #contact also?

    • @zoebai7991
      @zoebai7991 6 років тому +2

      @Parmesan yep I understand what you mean, but what value exactly in the current panel matches target value? The current panel is just an element , whereas the target value is either"contact" or "about".

    • @patrickmckenna6520
      @patrickmckenna6520 5 років тому

      @@zoebai7991 The current Pannel is an element the targetPannel is also an element as the dataset returns an id which is then used to save that element. The attributes of both are not being compared the elements themselves are to see if they are the same one.

    • @ronaldv.7931
      @ronaldv.7931 4 роки тому

      @@patrickmckenna6520 are you sure about that? I think "e.target" would return the element, and "e.target.dataset.target" would return the value of attribute data-target

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

      e.target returns the li element clicked
      e.target.dataset returns a mapping
      where i think the key is target and the value is the entire div
      if u console log e.target.dataset.target AKA targetpanel it shows the entire div

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

    Nice video! Just one thing to notice.. in the event listener added to tabs we could have checked whether the target li tag was already having class set as active or not and only proceed to change it when it wasn't active. This way setting the class attribute in the li tag would have been of some use.

  • @rFootprint
    @rFootprint 6 років тому

    Great! This is what I've been looking for! Thank you Ninja!! :)

  • @codingevelynmiami4230
    @codingevelynmiami4230 6 років тому

    Absolutely brilliant. Thanks.

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

    Thanks Brother!
    This is with the Spread operator && arrow functions
    tabs.addEventListener('click', (e) => {
    if (e.target.targetName == 'li') {
    const targetPanel = document.querySelector(e.target.dataset.target);
    [...panels].forEach((panel) => {
    log('foreach: ', panel);
    if (panel == targetPanel) {
    panel.classList.add('active');
    } else {
    panel.classList.remove('active');
    }
    });
    }
    });

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

    Thank you very much!!!!

  • @nikosspiropoulos8417
    @nikosspiropoulos8417 5 років тому +4

    Hello, could someone explain what this "Data-target" actually is and how it works? Thank you very much!

    • @bellybuttondoctor
      @bellybuttondoctor 5 років тому +8

      It's just a custom data attribute like 'src' in link tags or 'class' or 'id' in div tags. Those are all html standard. If you want a custom one, you just preface it with "data-'name'". So, 'data-target', 'data-key', 'data-whatever' are all legal custom attributes.

  • @EpicFail89fun
    @EpicFail89fun 7 років тому +2

    In the last if you are comparing element from Node list to a string which contains id. How does it work that "if"? It returns true while there are a lot of other data inside this node so how it know that it has to mach this exactly id not for example class or element name?

    • @pastuh
      @pastuh 6 років тому

      console.log('TARGET: ' + targetPanel.outerHTML);
      panels.forEach(function (panel) {
      console.log('LOOP: ' + panel.outerHTML);

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

    Nice.. is there simple way to fade in a active content and or fade out none-active?
    (for all browsers)

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

      Ok.. I looked into it a tiny.. and found the concept or property, opacity.
      Of cause from color to background color should also work.
      I have to test this regarding flickering and "large" div element with lot's of information and components (tag's) on.

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

    your best

  • @0the0ambient0
    @0the0ambient0 7 років тому

    Great series

  • @1MelkaZ
    @1MelkaZ 7 років тому

    Thank you Ninja master.

  • @boboboboboboo7522
    @boboboboboboo7522 6 років тому

    useful tutorial thanks

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

    Question.. on line 66 why do we need to put "capital" "LI"? I tried with a lowercase and it doesn't work. what's the difference between the lowercase and uppercase "LI" tag?

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

      Hey, this is just the way the document object describes target elements - in uppercase. In JavaScript, lowercase strings do not equal uppercase strings, they are considered different.

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

      @@NetNinja thank you for the reply! What should I search to read more about this in the documentation? Thanks again!

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

    On line 48 of html, there is a class of active. Can someone explain why is it there. There was no change in execution even if I removed the class

  • @hcx1853
    @hcx1853 7 років тому +1

    1. getElementsByClassName, getElementsByTagName returns *HTMLCollection*
    Array.from(titlesByClass).forEach(function(title){
    console.log(title);
    });
    2. querySelector, querySelectorAll returns *NodeList*
    titles.forEach(function(title){
    console.log(title);
    });

  • @levaninatenadze9644
    @levaninatenadze9644 5 років тому

    i want to click somewhere in this document and remove active class, how to do that?

  • @rudestewing
    @rudestewing 6 років тому

    thank you so much

  • @start1002001
    @start1002001 5 років тому +3

    tagName() returns all uppercase , it's a javascript weird part.

  • @zuber3228
    @zuber3228 6 років тому +10

    i got a job by this vidoe

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

    Why ''LI'' is in capital in the first if ?

  • @pastuh
    @pastuh 6 років тому

    Its correct way to remove active class from all tabs?
    if (panel === targetPanel) {
    panel.classList.add('active');
    Array.from(tabLi).forEach(function (li) {
    li.classList.remove('active');
    });
    e.target.classList.add('active');
    } else {
    panel.classList.remove('active');
    }
    Or this method?
    if (panel === targetPanel) {
    panel.classList.add('active');
    const activeLi = tabs.querySelector('.active');
    activeLi.classList.remove('active');
    e.target.classList.add('active');
    } else {
    panel.classList.remove('active');
    }

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

    why the "li" need to be uppercase "LI" ??

  • @Zero-ss6pn
    @Zero-ss6pn 4 роки тому

    Why did we use capital "LI" in e.target.tagName == "LI"

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

      html is not case sensitive you can use LI also and li also

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

    It would be better if you showed the end result while you were building it.