开发者

Jquery dom after .post

I have a .post that appends a string of divs inside another hidden div. I want to be able to click on those images and show one of those divs that were dynamically created. The post sends back a json array. When I loop through that array I do this...

string += '<div id="div2'+variable+'">'+value+'</div>';
$("div1").append(string);

I need to be able to click on a different element and show that dynamically created div (div2 plus the variable so ) in a jquery dialog. I have tried this but I assume si开发者_如何学JAVAnce it was created after the post request it is not in the DOM.

function showdiv(variable){        
    $("div2"+vairable).dialog('open');
}


Create the element like this

var new_div = $('<div/>');
new_div.attr('id', 'div' + variable)
       .html(value);

Then add an event handler to the other element:

other_element.click(function() {
   $('#div' + variable).dialog('open');
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜