javascript - Adding existing canvas to a div dynamically -


i have problem adding existing canvas div dynamically via jquery. try numerous options append 1 works.

here code:

<div class="a">      <div id="b"></div>      <div id="c" class="c">      </div>  </div> 

jquery:

$(document).ready(function() {     if($('.mydivifload').text().length >= 0)     {         //$('canvas[class="canvasclass"]').appendto($('.c')); // doesn't work         //$('canvas[class="canvasclass"]').append($('.c')); // doesn't work         //var canv= $('canvas[class="canvasclass"]'); //doesn't work         //document.getelementbyid('c').appendchild(canv)        // doesn't work         $('canvas.canvasclass').appendto('.c')         $(function()         {              $(".a").hover(function()             {                  $(".a").stop(true, false).animate({right: "0" }, 800, 'easeoutquint' );              }, function()             {                  $(".a").stop(true, false).animate({right: "-245" }, 800, 'easeinquint' );              },1000);          });      } }); 

if me grateful!

edit

if depends in code based on tutorial: http://w3lessons.info/demo/sliding-facebook-likebox/

four things:

  1. in css, identifiers (id values, class names) cannot start digit, selector .3 invalid (as selector #1, etc.). (you've said below aren't real ids , classes, , real ones don't start digits.)

    consider starting ids , class names letter selectors valid.

  2. your appendto, not append, right way go, selector problem.

  3. canvas[class="canvasclass"] looks canvas exactly class canvasclass , no others. it'll match <canvas class="canvasclass">..</canvas>" not <canvas class="foo canvasclass">..</canvas> or similar. best way select class class selector, canvas.canvasclass, match element class (even if has others).

  4. this suspect: $('.mydivifload').val().length. class suggests it's div, divs don't have values. have contents. may want .text().length or .html().length or .children().length or .contents().length depending on goal line is.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -