jQuery - How to show/hide dynamically generated html elements
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();**
});
精彩评论