We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,780 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

toggle on/off embedded music

I'm trying to get this code to toggle between innerhtml - turn off embedded music. But it doesn't seem to be firing?

The html in question:

<span id="music">
<embed src="http://thewalshgroup.ca/dev/the-nest/music/12_full_prom-night_0132.mp3"autostart="true" loop="true"
width="2" height="0" id="player"> <noembed> <bgsound src="http://thewalshgroup.ca/dev/the-nest/music/12_full_prom-night_0132.mp3"> </noembed>
</embed> 
</span>

and the jquery function:

$(document).ready(function() {

var playing = true;

$('#music_control').click(function() {

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

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

        playing = false;
        $("#music_control").text("MUSIC OFF");
      }

  });
}); 
2
Contributors
2
Replies
21 Hours
Discussion Span
2 Months Ago
Last Updated
13
Views
Question
Answered
turpentyne
Junior Poster in Training
84 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Self-Answered as of 2 Months Ago

Care to share your solution to help others?

pritaeas
Posting Prodigy
Moderator
9,267 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,456
Skill Endorsements: 86

Sure! Sorry about that!

For the jquery, I put:

$(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'> ");




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



      } else if (playing == true) {
      playing = false;

         $('#music').html("<!-- asdf -->");


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

      } 


  }); 



}); 

and in the html I had a link control and the div to switch:

<a href="#" id="music_control" class="">MUSIC OFF</a>


<div 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">
    </embed> 
</div>
turpentyne
Junior Poster in Training
84 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0625 seconds using 2.72MB