1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[Help] Javascript code help needed

Discussion in 'HTML & JavaScript' started by Tpati, Nov 29, 2015.

  1. Tpati

    Tpati Registered Member

    Joined:
    Sep 12, 2015
    Messages:
    92
    Likes Received:
    40
    I want to know how can I hide a certain class when another class is active,
    The concept is surely clear but I am unable to code it.
    So what I want to do basically is :
    when class XYZ is active I want to hide class ABC.
    oblige :)
     
  2. NachoMan

    NachoMan Newbie

    Joined:
    Sep 15, 2010
    Messages:
    18
    Likes Received:
    4
    document.getElementsByClassName returns a Collection of all the elements matching the class name.


    You can access the element you want using the bracket with the index or subscript notation.


    document.getElementsByClassName('appBanner')[0].style.visibility='hidden';
    Hope it helps!
     
  3. ghackseo

    ghackseo Regular Member

    Joined:
    Mar 18, 2015
    Messages:
    283
    Likes Received:
    72
    Hi OP, I quickly wrote this as something basic to start off with: http://plnkr.co/edit/8riKUcAl2A1AazP2aYSl?p=preview

    basically, you'll see the script checking for a class (this will be your active class), if it finds it, it will change the class (here you can add whatever other class) of whatever element you want. Hope it makes sense :)
     
  4. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,612
    Likes Received:
    11,241
    Occupation:
    Pusillanimous Knitter
    Location:
    Buenos Aires
    Thread moved to the proper section.
     
  5. dblane4

    dblane4 Junior Member

    Joined:
    Nov 8, 2015
    Messages:
    118
    Likes Received:
    16
    Occupation:
    Freelance web developer
    Location:
    ┌∩┐
    Use jQuery add/remove method.
    $('element').addClass('show').removeClass('hide');
     
  6. revproxy

    revproxy BANNED BANNED Jr. VIP Premium Member

    Joined:
    Nov 20, 2015
    Messages:
    396
    Likes Received:
    100
    Gender:
    Male
    you can use :visible jQuery selector
     
  7. flaveris

    flaveris Newbie

    Joined:
    Jul 12, 2013
    Messages:
    16
    Likes Received:
    2
    Occupation:
    Web Developer
    Home Page:
    You can use jQuery's .toggle() method as well.