简体   繁体   中英

dynamically add HTML & flash object from jQuery

I have this code where I am trying to generate this block of through jQuery. Plus there is even flash script in the html code.

<div class="span4" style="margin-bottom: 30px; position: relative"  >
   <h5>Reverse Video for</h5>
   <button class="modal-close pull-right">&times;</button>
    <div id="student-video1" >
     <script>
        swfobject.embedSWF(swfLoader, "student-video1", "300", "200", 
        swfVersionStr, xiSwfUrlStr, flashvars, this.params, {id: 'student-video-object', name: 'student-video-object'});
     </script>
    </div>
</div>

And I am trying to inject this div dynamically on click of a button in jQuery

var div = $('<div class="span4" style="margin-bottom: 30px; position: relative"  >
                <h5>Reverse Video for</h5>
                <button class="modal-close pull-right">&times;</button>
                <div id="student-video1" >
                  <script>
                    swfobject.embedSWF(swfLoader, "student-video1", "300", "200", 
                    swfVersionStr, xiSwfUrlStr, flashvars, this.params, {id: 'student-video-object', name: 'student-video-object'});
                  </script>
                </div>
              </div>');

    $('.container').before(div);

I think I am doing it wrong, as its not working. Any suggestions ?

You should use \\ to escape multi-line string like,

var div = $('<div class="span4" style="margin-bottom: 30px; position: relative">\
            <h5>Reverse Video for</h5>\
            <button class="modal-close pull-right">&times;</button>\
            <div id="student-video1" >\
              <script>\
                swfobject.embedSWF(swfLoader, "student-video1", "300", "200", swfVersionStr, xiSwfUrlStr, flashvars, this.params, {id: \'student-video-object\', name: \'student-video-object\'});\
              </script>\
            </div>\
          </div>');

$('.container').before(div);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM