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 187667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:51:51+00:00 2026-05-11T15:51:51+00:00

I am trying to change the class of an element using javascript. So far

  • 0

I am trying to change the class of an element using javascript. So far I’m doing :

var link = document.getElementById('play_link'); link.className = 'play_button'; 

edit: here is the actual code that replace the classname

In the HTML :

<a href='#play_link_<%=i%>' id='play_link_<%=i%>'onclick='changeCurrentTo(<%=i%>);return false;' class='play_button'></a> 

In the Javascript function changeCurrentTo(id){ activatePlayButton(current_track); current_track = id; inactivatePlayButton(current_track); }

function inactivatePlayButton(id){     document.getElementById('recording_'+id).style.backgroundColor='#F7F2D1';     var link = document.getElementById('play_link_'+id);     link.className='stop_button';     link.onclick = function(){stopPlaying();return false;}; }  function activatePlayButton(id){     document.getElementById('recording_'+id).style.backgroundColor='';     var link = document.getElementById('play_link_'+id);     link.className = 'play_button';     var temp = id;     link.onclick = function(){changeCurrentTo(temp);return false;}; } 

with

.play_button{     background:url(/images/small_play_button.png) no-repeat;     width:25px;     height:24px;     display:block; } 

the old class is

.stop_button{     background:url(/images/small_stop_button.png) no-repeat;     width:25px;     height:24px;     display:block; } 

The context is a music player. When you click the play button (triangle) it turns into a stop button (square) and replace the function that is called.

The problem is that the class get changed, but in IE6 and 7 the new background (here /images/small_play_button.png) does not display right away. Sometime it doesn’t even display at all. Sometime it doesn’t display but if I shake the mouse a bit then it displays.

It works perfectly in FF, Chrome, Opera and Safari, so it’s an IE bug. I know it’s hard to tell right away from only these information, but if I could get some pointers and directions that would be helpful.

Thanks-

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T15:51:51+00:00Added an answer on May 11, 2026 at 3:51 pm

    You should create one image with a width of 50px and a height of 24px where you have both the play part and the stop part. Then you just ajust the background position like this:

     .button {     background-image: url(/images/small_buttons.png);     bacground-repeat: no-repeat;     width: 25px;     height: 24px;     display: block; }  .play_button {     background-position: left top; }  .stop_button {     background-position: right top; }

    Then you load ‘both images’ at the same time, and no delay will happen when you change which part of the image gets displayed.

    Note that I have made a new CSS class so that you dont need to repeat your CSS for different buttons. You now need to apply two classes on your element. Example:

    <div class='button play_button'></div>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 391k
  • Answers 391k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer the Take Away part means that the design can be… May 15, 2026 at 1:22 am
  • Editorial Team
    Editorial Team added an answer Another alternative is to use the Google ChartAPI: http://code.google.com/apis/chart/docs/gallery/pie_charts.html May 15, 2026 at 1:22 am
  • Editorial Team
    Editorial Team added an answer Check for memory leaks on the device, rather than on… May 15, 2026 at 1:22 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.