Brian, thanks very much, really appreciate it.
On Dec 16, 12:41 am, brian <zijn.digi...@gmail.com> wrote: > Try this: > > function CreateNewElement() > { > $('<div id="div1">test content</div>') > .appendTo('#contentContainer') > .hide() > .toggle('slow'); > > } > > You'll likely want to change the ID and, obviously, the content. But > the principal i the same--jQuery can take the string markup and create > the element on the fly. > > Note that the hide() is necessary. Otherwise, the toggle() will hide > the element as it will be visible by default. > > > > On Tue, Dec 15, 2009 at 11:29 AM, Ham <grahamhw...@googlemail.com> wrote: > > Hi, > > > Im new to Jquery and have been trying to dynamically create a new div > > element with document.createElement. > > > I can successfully insert this element into the dom but I want to > > animate it on creation. After inserting the element into the DOM i try > > and access it using a JQuery selector but it does not seem to find it. > > > Example code. > > > function CreateNewElement() > > { > > > var container = $("#contentContainer"); > > var myDiv = (document.createElement('div')) > > myDiv.setAttribute("id", "div1"); > > myDiv.innerHtml = "test content"; > > container.appendChild(myDiv); > > > $("div1").toggle("slow"); > > > } > > > Any help greatly appreciated. > > > Many Thanks > > Ham