Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
Like Tree3Likes
  • 1 Post By TheGAME1264
  • 2 Post By Ronald Roe

Thread: swapping two using class properties querySelector

  1. #1
    Member
    Join Date
    Jun 2014
    Posts
    37
    Member #
    39433
    Liked
    1 times

    swapping two using class properties querySelector

    Hello, I would like to swap both the background color and border color of the div.
    at the moment it is only swapping the backrgroud color
    i would also like so that the border and background not the same color at one time.

    html:
    Code:
    <div class="hi"></div>
    javascript:
    Code:
    var colors = ['green', 'orange', 'blue'];
    var active = 0;
    setInterval(function(){
        document.querySelector('.hi').style.background = colors[active];
        active++;
        if (active == colors.length) active = 0;
    }, 5000);
    css:
    Code:
    .hi {
        background: blue; /* initial color */
        width:200px;
        height:200px;
        transition: background 0; /* 0s how long transition should take */
        border-style: solid !important;
        border-width: 15px 15px 15px 15px !important;
     border-color:cyan !important;
     border-radius: 0px !important;
    }

  2.  

  3. #2
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,485
    Member #
    425
    Liked
    2783 times
    This will set you up so that your border and foreground color match and are different from the background color. They'll always be the color "after" the background color. Your homework, since I helped you, is to tell me why.
    Code:
    var colors = ['green', 'orange', 'blue'];
    var active = 0;
    setInterval(function(){
        document.querySelector('.hi').style.background = colors[active];
        active++;
        if (active == colors.length) active = 0;
        document.querySelector('hi').style.borderColor = colors[active];
        document.querySelector('hi').style.color = colors[active]
    }, 5000);
    452wfr234 likes this.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  4. #3
    Member
    Join Date
    Jun 2014
    Posts
    37
    Member #
    39433
    Liked
    1 times
    Quote Originally Posted by TheGAME1264 View Post
    This will set you up so that your border and foreground color match and are different from the background color. They'll always be the color "after" the background color. Your homework, since I helped you, is to tell me why.
    Code:
    var colors = ['green', 'orange', 'blue'];
    var active = 0;
    setInterval(function(){
        document.querySelector('.hi').style.background = colors[active];
        active++;
        if (active == colors.length) active = 0;
        document.querySelector('hi').style.borderColor = colors[active];
        document.querySelector('hi').style.color = colors[active]
    }, 5000);
    thanks i am a total noob, but it works great

  5. #4
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    Oooh. Oooh. ME! I KNOW!!!!
    TheGAME1264 and Vapr_Arts like this.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  6. #5
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,485
    Member #
    425
    Liked
    2783 times
    I know you know, Ron. But it's not your ​homework.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:45 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com