jquery
2017-08-18 2 views 1 likes 
1

私はこれについて質問したいと思っています: "子供を他の要素に置き換え、親を維持してから文書に適用する方法。" 私はreplaceWith()で試しましたが、解決策を教えてくれませんでした。私はテンプレートギャラリーが 感謝:-)要素のビデオを持って欲しい子供を交換して親を維持する

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{ 

     } 
    } 

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: はここに私のコードです。

答えて

0

html関数を使用して子を追加するよりも、ターゲットの親を識別するためにjQueryを使用するだけです。

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

あなただけのこの操作を行うよりも、既存のDOM要素と交換したい場合は...

$('#parent-div').html($('#divIWant')); 
+0

私の質問は、他の要素、仲間と交換する方法です。私のtemplate_galleryは関数html()でも適用されるからです。 – user8455694

+0

更新しました –

関連する問題