Problem using the prependTo() in jQuery

Posted by raulriera on Stack Overflow See other posts from Stack Overflow or by raulriera
Published on 2010-03-15T06:13:41Z Indexed on 2010/03/15 6:19 UTC
Read the original article Hit count: 260

Filed under:
|

Hi all,

I am having a problem trying to use the prependTo() function in jQuery... for some reason I can't get this to work

$("
<div id="note178" class="note"> 
 <div class="delete"><a href="/chart-notes/delete/178" onclick="$.ajax({ dataType: 'script', url: '/chart-notes/delete/178'}); return false;"><img src='/images/icons/delete.png'></a></div> 
 <div class="timestamp">1 minute ago </div> 
 <div class="content">ñasdas dasdasdasd conclusión</div>  
</div>
").prependTo(".notes").fadeIn("slow");

Although when doing it like this, it works fine

$.ajax({
  url:'/chart-notes/show/<cfoutput>#chartnote.id#</cfoutput>',
  success: function(data) {
   $(data).prependTo(".notes").fadeIn("slow");

   // Scroll to the top of the annotations
   $('html, body').animate({scrollTop: $(".notes").offset().top}, 1000);

   // Clear the form
   $('#chartnote-notes').val("");  
  }
 });

The "data" response from that success function is the same

<div id="note178" class="note"> 
 <div class="delete"><a href="/chart-notes/delete/178" onclick="$.ajax({ dataType: 'script', url: '/chart-notes/delete/178'}); return false;"><img src='/images/icons/delete.png'></a></div> 
 <div class="timestamp">1 minute ago </div> 
 <div class="content">ñasdas dasdasdasd conclusión</div>  
</div>

As before

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about prepend