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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:01:31+00:00 2026-06-08T23:01:31+00:00

I have a player that is triggered with jQuery. I may have several players

  • 0

I have a player that is triggered with jQuery. I may have several players on a single page but a single ‘miniPlayer’ in the toolbar. The player toolbar needs to play/pause etc if another player event is triggered. For this to happen I need to only replace the class inside the player element.

The player in the toolbar has an id of #miniPlayer and all other players will just be #player, this is for styles. Because of this I can only replace the class within the element so that the styles are not changed for the miniPlayer if a button in the player is clicked, or visa versa.

Mini Player (play);

<a id="miniControls" class="play" href="" title=""></a>

Will become;

<a id="miniControls" class="pause" href="" title=""></a>

Onclick of either the miniPlayer pause button or the normal player pause button.

Normal Player (play);

<a id="controls" class="play" href="" title=""></a>

Will become;

<a id="controls" class="pause" href="" title=""></a>

Onclick of either the miniPlayer pause button or the normal player pause button.

The jQuery I have at the moment will replace the miniplayer, if the normal player (play) is clicked with;

<a id="controls" class="pause" href="" title=""></a>

But the id needs to stay as miniControls for the styles. This will be the opposite but same problem if the miniPlayer is clicked.

Play/Pause functions in jquery script (only works for miniPlayer at the moment):

play.live('click', function(e) {
    e.preventDefault();
    song.play();

    $('.play').replaceWith('<a id="miniControls" class="pause" href="" title=""></a>');

    $('.seek').attr('max',song.duration);
});

pause.live('click', function(e) {
    e.preventDefault();
    song.pause();
    $('.pause').replaceWith('<a id="miniControls" class="play" href="" title=""></a>');

});

Is there a way to only replace the class so i’d just replace $(‘.pause’) with $(‘.play’) instead of the whole <a> tag. I’ve had a look on the jquery website but couldn’t find anything. Maybe I am looking at it at the wrong angle.

  • 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-06-08T23:01:34+00:00Added an answer on June 8, 2026 at 11:01 pm
    $('#miniControls').click(function(e){
        e.preventDefault();
        $(this).hasClass('play') ? song.pause():song.play();
        $(this).toggleClass('play pause');
    });
    

    You can greatly reduce your code by using something like the above example. In this case you would use .toggleClass() to switch between the play and pauses classes and also use .hasClass() to determine which action to perform.

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

Sidebar

Related Questions

I have an mp3 player that sends MCI commands to play pause/ff/rw/stop the audio
I have a tables 'players' and 'awards'. I have some duplicate player entries that
I have a page with multiple YouTube embedded players that I need to listen
I have an audio player that i built with jquery. The markup and css
I have a music player that links to a song using the following syntax:
I have a flash player that loads in some additional features from flash files
I have a class Player that contains a list of Accessory objects. There are
I'm having an issue where I have a player object that I'm trying to
I have a Rails app implementing a game, so it's expected that a player
I have seen on many sites the silverlight video player. I noticed that all

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.