jquery soundcloud play/stop

How can I add the CSS-Class "playSound", during the track plays?

jQuery(document).ready(function($)
    {
        var widget = SC.Widget(document.getElementById('soundcloud_widget'));

        /*widget.bind(SC.Widget.Events.READY, function()
        {
            //console.log('Ready...');
            jQuery(".checkSound").removeClass('stopSound').addClass('playSound');
        });*/

        jQuery('.playSound').click(function()
        {
            widget.toggle();
            jQuery(".playSound").addClass('stopSound');
        });

        jQuery('.stopSound').live(function()
        //jQuery(".stopSound").live("click", function()
        //jQuery('.stopSound').click(function()
        {
            jQuery(".stopSound").addClass('playSound').removeClass('stopSound');
        });
    });

Answers


I have never used SoundCloud, but it appears that you are trying to use the same element to both play and stop. If that is the case, this should work:

jQuery(".playSound,.stopSound").click(function(){
    jQuery(this).toggleClass("playSound stopSound");
    widget.toggle();
});

The click event will presumably be bound to a single element. The selector .playSound,.stopSound is to make sure it selects the element regardless of what class it starts out with. .toggleClass() will remove class if they are in the list or add classes if they are not. And I'm assuming widget.toggle() was working as expected.


Need Your Help

How to get a Facebook access token on iOS

iphone facebook access-token

iOS beginner here. I have the following code:

Emberjs, server side vs client side, All in?

php javascript rest yii ember.js

I have been looking into Ember.js, and it looks really great, but one thing that concerns me, and that I can't get my mind around it, is if I start using it on an already running project.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.