javascript - How to add or bind classes to both parent and child elements of dynamically loaded data using ajax call? -
i new jquery , struggling here past 1 week.i loading data json array using ajax call, , using 1 "swipe" plugin swipe , load images on page on same div. don't know how add class both parent div , child elements. code is:
url : "http://my_ip/app/event_h/get_a_evnts", type:"post", datatype:"json", success: function(data) { var event1=data.event1; var total_event=event1.length; var event1=data.event1; var dom=$('#dom'); var path="http://my_ip/app/"; var media1=data.media; var location=json.location; var event2=data.event; var rating=data.rating; var event1[i].event_id =1;//this value retrived json array var output= '<div class="container-fluid" ><section class="row">'; output +='<div class="col-sm-12 col-md-12 col-xs-12"><div class="panel panelstyle">'; output +='<header><h1><small>event : </small>'+event1[i].event_title+'</h1></header><div class="panel-body">'; output +='<div id="div1" class="swiper-container" ><div id="div2" class="swiper-wrapper" >'; for(j=0; j<media1.length; j++) { if(event1[i].event_id === media1[j].event_id){ output +='<img id="newimg" class="swiper-slide" src='+path+media1[j].media_path+' alt="new image" />'; } }});
i didn't write complete code here required part have written in above code works fine not single error in console .swiper-container,.swiper-container,.swiper-slide not loading when page loads cannot swipe images. have tried "on","delegate" "bind" unable attach class when page loads.
try code:
output = $(output); output.addclass(".swiper-container");
Comments
Post a Comment