making jquery object from variable does not fully work -


i'm pretty new jquery , encountered problem. use $() make variable jquery object. somehow, not work expected (i'd expect can access jquery methods object). here did:

$(function() {     var form = "<div id='menu-box'></div>";     $(form).appendto('body').css({'backgroundcolor': 'blue'});  // line works     $(form).css({'backgroundcolor': 'red'});  // line not.  }); 

i'm using jquery-1.9.1, bug or did wrong.

each time write $(form), new jquery object constructed wraps newly-created <div>. second time happens, operating on element has not been inserted dom.

consolidate 2 usages instead desired result (although of course not make sense "real" code):

var $form = $("<div id='menu-box'></div>"); $form.appendto('body').css({'backgroundcolor': 'blue'}); $form.css({'backgroundcolor': 'red'}); 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -