views:

974

answers:

2

Hello, I am having a problem with selecting an element from a previously loaded html page

if I use this code, the one before last is designated too be the last in the dom-tree instead of the one that I just inserted

$("div.wrapper:last").after('<div class="wrapper"></div>'); 
    $('.wrapper:last').load('tbnote.html .pane');
    $(".pane:last").prepend("testmessage");

What can I do, too make it work, because I need too set the hidden field value too the primarykey value of a database table

if it is not possible, what would be an alternative to get the content in the div with the hiddenfieldvalues already set??

Thanks in advance, Richard

+1  A: 

Try this:

$('.wrapper:last').load('tbnote.html .pane', function() {
   $(".pane:last").prepend("testmessage");});

I'm not sure what you are actually want to achieve, but a common error among developers new to jQuery is to consider that ajax functions execute instantly. On the contrary the loading of the remote html will happen asynchronously and you need to use the optional callback function.

kgiannakakis
A: 

thankyou, so it doesn't work the same as include with php

how would I use a callback in this particular case oh,I see, you gave me the answer, I was too quick in answering. I will try that first

what I want to achieve is to get stickynotes on the page and each new one placed underneath it

like this example, but in the example they are already made

in the example, it fades the the div, whem you click the delete button mine also deletes the message from the database, so somewhere I have to place the messageid in that div, so it can delete the right message

Richard