Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7596321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:53:29+00:00 2026-05-30T21:53:29+00:00

So forgive me, I’m just starting learning Javascript, I don’t even know if this

  • 0

So forgive me, I’m just starting learning Javascript, I don’t even know if this is possible. I have the following HTML code:

<div class="container">
<div class="topspace">
    <div id="picholder" class="pic1">
        <div class="picsel" id="picsel1" onclick="imgSel(1)"></div>
        <div class="picsel" id="picsel2" onclick="imgSel(2)"></div>
    </div>
</div>
</div>

And so what I want to accomplish is by clicking on one of the “picsel” divs (they appear as little squares at the bottom of the picholder div) I can change the backgroundImage used in picholder by changing the class associated with the picholder div. My Javascript appears as such:

function imgSel(n) {
var id1 = "pic" + n;
var id2 = "picsel" + n;

// 'zero out' all the picsel boxes to their default color
document.getElementByClass('picsel').style.backgroundColor="#333";
// change the background-image for picholder
document.getElementById('picholder').style.className=id1;
// change the picsel box that was clicked to white
document.getElementById(id2).style.backgroundColor="#FFF";
}

And my CSS appears as such:

#picholder {width:798px; height:340px; border:1px solid #333; background-color:#333;}
.picsel {width:8px; height:8px; background-color:#333; border:1px solid #333; margin-left:4px; top:340px; position:relative; float:left;}
.picsel:hover {cursor:pointer; background-color:#888;}
.pic1 {background-image:url('data/main001.jpg');}
.pic2 {background-image:url('data/main002.jpg');}

I’ve run an Alert on it and the variables are being added right, so I guess what I’m wondering is, is it possible to change the className (or is that even a command?). At this point I’m thinking I can’t assign a variable to the className=var or getElementById(var), but…well…have at it.

It’s currently running at http://www.mdw-art.com/, but in an HTML-based version that doesn’t indicate which square is currently being displayed. So I basically want it to do that, but I’m trying to get the boxes to indicate which one is currently displayed and get the code out of the HTML (because I want to apply this same concept to other galleries later).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:53:30+00:00Added an answer on May 30, 2026 at 9:53 pm

    Yes, add a class name to the selected item and allow the CSS of that class do the work for you instead of changing the inline style with JavaScript. That way you can just remove the class name from the element to un-do the selection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Forgive a newbie, I don't even know how to ask this question properly: I
Forgive this novice question (novice in Javascript!). In a html page I have a
Forgive my ignorance if this is 'a basic question'..... I have a method that
Forgive me, but I don't know the technical term to know what to search
Forgive me if my understanding of this topic has some shortcomings, I only know
Forgive me if this has already been asked elsewhere. I have a Scala syntax
Forgive me for this is a very simple script in Bash. Here's the code:
Forgive me if this post is too naive-sounding. I have a Twitter app that
Forgive me if this has already been asked, I couldn't find it. I have
forgive me in advance, I ride the javascript short bus :( I have the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.