Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    405
    Thanks
    17
    Thanked 2 Times in 2 Posts

    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.

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    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

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,607
    Thanks
    6
    Thanked 997 Times in 970 Posts
    <bgsound>? Are you serious?

  • #4
    Regular Coder
    Join Date
    Aug 2010
    Posts
    405
    Thanks
    17
    Thanked 2 Times in 2 Posts
    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?

  • #5
    Regular Coder
    Join Date
    Aug 2010
    Posts
    405
    Thanks
    17
    Thanked 2 Times in 2 Posts
    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"); 
             
          } 
    
    
      });


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •