How to position a DIV on DOM ready after it has been created
<p>I am trying to create a page where I can attach sticky notes at runtime exactly as explained in this <a href="http://demo.tutorialzine.com/2010/01/sticky-notes-ajax-php-jquery/demo.php" rel="nofollow">tutorial</a>.</p>

<p>I have converted the sample in ASP.NET MVC 2 (which is the technology I am using) and everything works fine.</p>

<p>So I have a DIV in my view</p>

<pre><code>&lt;!-- Contains all the notes and limits their movement --&gt;
&lt;div id="notesDesktop" style="margin: 0 auto; position:relative;"&gt;
&lt;/div&gt;
</code></pre>

<p>and, on DOM ready, I am setting his size to make it occupying all the space available respect to its container with this code</p>

<pre><code>$("#notesDesktop").width($("#sectionContent").width());
$("#notesDesktop").height($("#sectionContent").height() - $("#actionArea").height());
</code></pre>

<p>The only problem I am facing is that when I load the notes from database and create the related DIVs inside the "notesDesktop" they're not positioning correctly. The code is this one</p>

<pre><code>&lt;div id="notesDesktop" style="margin: 0 auto; position:relative;"&gt;
   &lt;% List&lt;ContactNoteModel&gt; list = (List&lt;ContactNoteModel&gt;)ViewData["noteList"];
        foreach (ContactNoteModel cnm in list) { 
            string[] pos = cnm.Position.Split(new string[] {"x"}, StringSplitOptions.RemoveEmptyEntries);
    %&gt;
    &lt;div class="note &lt;%=cnm.Color%&gt;" style="left:&lt;%=pos[0]%&gt;;top:&lt;%=pos[1]%&gt;;z-index:&lt;%=pos[2]%&gt;;"&gt;
       &lt;div class="body"&gt;&lt;%=cnm.NoteText%&gt;&lt;/div&gt;
       &lt;div class="author"&gt;&lt;%=HttpContext.Current.User.Identity.Name %&gt;&lt;/div&gt;
       &lt;span class="data"&gt;&lt;%=cnm.ContactNoteID%&gt;&lt;/span&gt;
    &lt;/div&gt;
   &lt;%  } %&gt;
&lt;/div&gt;
</code></pre>

<p>that produces something like this</p>

<pre><code>&lt;div class="note yellow ui-draggable" style="left:43;top:269;z-index:4;"&gt;
   &lt;div class="body"&gt;This is a note!&lt;/div&gt;
   &lt;div class="author"&gt;admin&lt;/div&gt;
    &lt;span class="data"&gt;2&lt;/span&gt;
&lt;/div&gt;
</code></pre>

<p>As you can see the created DIV have absolute positioning values and its CSS class states that it should be positioned absolutely within its container. Anyway, despite this fact he's positioning to top=0 and left=0 :(</p>

<p>I suspect that this happens because when the notes DIV are created dinamically the container DIV still has'nt fixed height and width (which will be set on DOM ready of course) and so the elements can not be absolute positioned inside it.</p>

<p>Of course I could change my view to create dinamically the notes div on DOM ready but before going to change all the code I was wondering if i can have some code to make them respect the positions they have meant to be to.</p>

<p>My english is not perfect so I hope to stated clearly my problem. Any suggestion on this?</p>

<p>thanks in advance for helping </p>
