1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to make a javascript tab active?

Discussion in 'JavaScript' started by RobertKM, Feb 7, 2015.

  1. #1
    If you visit this page http://www.movienewsplus.com/p/dvd-blu-ray.html you will see the "Jan" and "Feb" tabs. Is there a simple way to make the "Feb" tab active, so when someone visits the page the "Feb" tab and its contents load?
     
    RobertKM, Feb 7, 2015 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    Well, first of all, it would be better if you gave each tab an id to reference it with, rather than look for the text in the title for the tab... but if that's not an option, this is the JS to do it:
    $('a[title="Feb"]').click();
    Code (javascript):
    Basically just triggering the JavaScript that runs when someone clicks that tab.
     
    digitalpoint, Feb 7, 2015 IP
  3. RobertKM

    RobertKM Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    Thank you Shawn. Pardon me for my lack of knowledge in JS (that's why I'm here :)), but where would I put that code? And this code would load the "Feb" tab first, instead of the "Jan" tab?
     
    RobertKM, Feb 7, 2015 IP
  4. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #4
    The simplest thin to do would just be to wrap it in <script> HTML tags and put it in your page source towards the end (it would need to be after where the tab is located in the HTML source...
    <script>
        $('a[title="Feb"]').click();
    </script>
    HTML:
     
    digitalpoint, Feb 7, 2015 IP
  5. RobertKM

    RobertKM Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    Hmm. That didn't seem to change anything. I moved it around in the source code and still nothing.
     
    RobertKM, Feb 7, 2015 IP
  6. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #6
    Sounds like the tabs might be loading dynamically after the page loads then... in that case, try this:

    <script>
        $(document).ready(function() {$('a[title="Feb"]').click();}
    </script>
    HTML:
    That will wait to fire it until the page DOM is loaded.
     
    digitalpoint, Feb 7, 2015 IP
  7. RobertKM

    RobertKM Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #7
    I got it worked out. It was just a matter of putting class="tabbertab tabbertabdefault" in the DIV. I appreciate you taking the time to try and help Shawn..Peace!
     
    RobertKM, Feb 7, 2015 IP
  8. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #8
    Depending on what the desired end result is, wouldn't it be better checking which month is the current month, and activate that tab?
     
    PoPSiCLe, Feb 8, 2015 IP
  9. RobertKM

    RobertKM Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #9
    That would probably be ideal for a more prolific coder than myself. That's OK, though, I don't mind doing it manually once a month.
     
    RobertKM, Feb 8, 2015 IP
  10. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #10
    My answer? Don't use inaccessible scripttardery BS, and if you do make it work without scripting FIRST, then enhance it. That scripting should change the URL in the address bar, and only supplant the functionality instead of replacing it.

    Scripted tabs is just as stupid and inaccessible a train wreck as framesets were -- it's basically replicating the same functionality and completely missing the point of accessible design.

    It's the unwritten rule of JavaScript -- "If you can't make the page work without scripting FIRST, you likely have no business adding scripting to it.". Good scripting should enhance functionality, not supplant or provide it.

    You seem to be doing stuff that honestly should probably be done server side in something like PHP or ASP, instead of dicking around with it client-side.
     
    deathshadow, Feb 13, 2015 IP
  11. RobertKM

    RobertKM Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #11
    The site is hosted with a free service, which doesn't allow access to the server. Currently, I'm making due with what I have to work with. It's just a simple script that does what I want, without causing much of a fuss.

    I can't really respond to the rest of your comments, as I would have to be in a position to understand what your saying in the first place.
     
    RobertKM, Feb 13, 2015 IP