开发者

jQuery - How to show/hide dynamically generated html elements

开发者 https://www.devze.com 2023-04-03 15:22 出处:网络
I have the following code. The html elements with the class \".acc_container\" are created dynamically through an AJAX call, so they don\'t exist yet when the code $(\'.acc开发者_StackOverflow_contain

I have the following code. The html elements with the class ".acc_container" are created dynamically through an AJAX call, so they don't exist yet when the code $('.acc开发者_StackOverflow_container').hide(); is executed. Is there something I can do here similar to the .live function for event binding?

$(document).ready(function () {
    $('.acc_container').hide();
    $.ajax({
        type: 'GET',
        url: 'Sample.xml',
        dataType: 'xml',
        success: function (xml) {
        //Tags with ".acc_container" class created here


You can control it easily through CSS.

.acc_container{
   display:none;
}

Whenever you want to show then use jQuery $(".acc_container").show();


I like ShankarSangoli's answer, however just be aware that ALL containers with that class will be shown, not just last one... You might want to control visibility via ID rather than class, if you can.


You can hide created element in AJAX callback function.

$(document).ready(function () {
    $.ajax({
        type: 'GET',
        url: 'Sample.xml',
        dataType: 'xml',
        success: function (xml) {

        //Tags with ".acc_container" class created here

        **$('.acc_container').hide();**
   });
0

精彩评论

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