Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-13-2013, 10:17 PM   PM User | #1
turpentyne
Regular Coder

 
Join Date: Aug 2010
Posts: 309
Thanks: 10
Thanked 1 Time in 1 Post
turpentyne is an unknown quantity at this point
cannot toggle innerhtml

I'm clawing my eyes out because this seems perfectly fine code, and yet it will not work. I just want a toggle to turn off some embedded music.


here's the html:
Code:
<a href="#" id="music_control" class="">MUSIC OFF</a>
<span id="music">
	<embed src="http://url.com/dev/music/12_full_prom-night_0132.mp3"autostart="true" loop="true"
width="2" height="0" id="player"> <noembed> <bgsound src="http://url.com/dev/music/12_full_prom-night_0132.mp3"> </noembed>
	</embed> 
</span>
and here's the jquery:
Code:
$(document).ready(function() {

var playing = true;


$("#music_control").click(function(){
 	
  		if (playing == false) {
  		playing = true;
          $('music').html("<embed src='http://url.com/dev/music/12_full_prom-night_0132.mp3'autostart='true' loop='true'
width='2' height='0' id='player'> <noembed> <bgsound src='http://url.com/dev/music/12_full_prom-night_0132.mp3'> </noembed>");
          $("#music_control").html("MUSIC ON"); 
           alert(playing);
           

      } else if (playing == true) {
      playing = false;
         $('music').html("<embed src='http://url.com/dev/music/12_full_prom-night_0132.mp3'autostart='false' loop='true'
width='2' height='0' id='player'> <noembed> <bgsound src='http://url.com/dev/music/12_full_prom-night_0132.mp3'> </noembed>");
        $("#music_control").html("MUSIC OFF"); 
        alert(playing);
      } 


  }); 

});

Last edited by turpentyne; 03-13-2013 at 10:19 PM..
turpentyne is offline   Reply With Quote
Old 03-13-2013, 10:28 PM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Music is an id so it should be $('#music'); your browsers' Console probably displayed an error message(?).

If the users' browser doesn't support the embed element then the music will probably still be playing (as bgsound). Why not just remove the element to stop the music.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 03-13-2013, 10:36 PM   PM User | #3
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,599
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
<bgsound>? Are you serious?
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 03-14-2013, 01:10 AM   PM User | #4
turpentyne
Regular Coder

 
Join Date: Aug 2010
Posts: 309
Thanks: 10
Thanked 1 Time in 1 Post
turpentyne is an unknown quantity at this point
actually, that's one of the things I'm trying. I was hoping to use "html()" to clear out the contents so there's nothing in the div. But it's not working. at all.

I fixed the #music, and it still has the same issues. Any thoughts?
turpentyne is offline   Reply With Quote
Old 03-14-2013, 01:45 AM   PM User | #5
turpentyne
Regular Coder

 
Join Date: Aug 2010
Posts: 309
Thanks: 10
Thanked 1 Time in 1 Post
turpentyne is an unknown quantity at this point
aha...

not even sure what I did.. but it's fixed with:

Code:
$(document).ready(function() {

var playing = true;


$("#music_control").click(function(){
 
  		
  		if (playing == false) {
  		playing = true;
        
          $('#music').html(" <embed src='http://url.com/music/12_full_prom-night_0132.mp3' autostart='true' loop='true' width='2' height='0' id='player'> ");


		
          
          $("#music_control").text("MUSIC OFF"); 
           
           

      } else if (playing == true) {
      playing = false;
        
         $('#music').html("<!-- x -->");

        
        $("#music_control").text("MUSIC ON"); 
         
      } 


  });
turpentyne is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:04 PM.


Advertisement
Log in to turn off these ads.