jquery - Replace children and keep parent -


i want ask question : "how replace children other element , keep parent applied document." tried replacewith() not give solution me. here code :

template_gallery = '<div class="mahbub-modal">'+         '<button type="button" class="mahbub-btn-close">'+elmahbub.btn_close+'</button>'+         '<div class="mahbub-modal-gallery">'+         '<div class="mahbub-gallery-content">'+         '<div class="mahbub-column-left">'+         '<img src="'+elmahbub.source+'" class="mahbub-image" alt="'+elmahbub.alt_image+'">'+         '<div class="mahbub-btn-more">'+         '<button type="button" class="mahbub-more-left" title="'+elmahbub.title_prev_button+'">&#10094;</button>'+         '<button type="button" class="mahbub-more-center" title="'+elmahbub.title_center_button+'">'+elmahbub.icon_btn_center+'</button>'+         '<button type="button" class="mahbub-more-right" title="'+elmahbub.title_next_button+'">&#10095;</button>'+         '</div>'+         '<div class="mahbub-gallery-footprint">'+elmahbub.title+         '<p class="mahbub-gallery-footprint-subtitle">'+elmahbub.sub_title+'</p>'+         '</div>'+         '</div>'+         '<div class="mahbub-column-right">'+elmahbub.content+         '</div>'+         '</div>'+         '</div>'; 

jquery :

if (elmahbub.type == 'video') {         video_element = '<video width="100%" height="500px" controls>'+         '<source src="'+elmahbub.source+'" type="video/ogg">'+         '<source src="'+elmahbub.source+'" type="video/mpeg">'+         elmahbub.error_load+'</video>';         if (elmahbub.gallery[0].enabled == false) {             template_gallery = $(template_gallery).children($('.mahbub-image')).replacewith(video_element);             modal = template_gallery;         }         else{          }     } 

i want template gallery have element video :-) thank.

just use jquery identify target parent, use html function append children.

$('#parent-div').html("<h1>test</h1>"); 

if want replace existing dom element this...

$('#parent-div').html($('#diviwant')); 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -