はwrap();
それ自体でうまく機能しますが、 の後に呼び出されるload();
と機能しません。
それを機能させるために何ができるでしょうか?wrap();
別の .js ファイル内にコードを入れようとしましたが、うまくいきませんでした。wrap();
inside:も読み込もうとしましたが$( window ).on( "load", function() { ... })
、それを html のフッター内に配置しましたが、問題は解決しませんでした。
これが私のコードです:
$('.page-id-202 #partner, .page-id-201 #partner').load('https://webhelytervezo.hu/ #gallery-1');
$(".gallery-item").each(function() {
$(this).wrap($("<a/>").attr("href", "http://" + $(".gallery-caption", this).text().trim()));
$("#gallery-1 a").attr('target','_blank');
});
figcaption{
display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="gallery-1" class="gallery galleryid-9 gallery-columns-3 gallery-size-full"><figure class="gallery-item">
<div class="gallery-icon landscape">
<img width="200" height="74" src="https://webhelytervezo.hu/wp-content/uploads/2022/01/cup_revolution_logo.jpg" class="attachment-full size-full" alt="" loading="lazy" aria-describedby="gallery-1-49">
</div>
<figcaption class="wp-caption-text gallery-caption" id="gallery-1-49">
www.web.cuprevolution.eu
</figcaption></figure><figure class="gallery-item">
<div class="gallery-icon landscape">
<img width="200" height="74" src="https://webhelytervezo.hu/wp-content/uploads/2022/01/areklam.jpg" class="attachment-full size-full" alt="" loading="lazy" aria-describedby="gallery-1-39">
</div>
<figcaption class="wp-caption-text gallery-caption" id="gallery-1-39">
www.areklam.hu
</figcaption></figure><figure class="gallery-item">
<div class="gallery-icon landscape">
<img width="200" height="74" src="https://webhelytervezo.hu/wp-content/uploads/2022/01/coca_cola.jpg" class="attachment-full size-full" alt="" loading="lazy" aria-describedby="gallery-1-48">
</div>
<figcaption class="wp-caption-text gallery-caption" id="gallery-1-48">
www.coca-cola.hu
</figcaption></figure><figure class="gallery-item">
<div class="gallery-icon landscape">
<img width="200" height="74" src="https://webhelytervezo.hu/wp-content/uploads/2022/01/arkad.jpg" class="attachment-full size-full" alt="" loading="lazy" aria-describedby="gallery-1-40">
</div>
<figcaption class="wp-caption-text gallery-caption" id="gallery-1-40">
www.arkad.hu
</figcaption></figure><figure class="gallery-item">
<div class="gallery-icon landscape">
<img width="200" height="74" src="https://webhelytervezo.hu/wp-content/uploads/2022/01/besttv.jpg" class="attachment-full size-full" alt="" loading="lazy" aria-describedby="gallery-1-41">
</div>
<figcaption class="wp-caption-text gallery-caption" id="gallery-1-41">
www.besttv.hu
</figcaption></figure>
</div>
1# と 2# を編集:
https://webhelytervezo.hu/から読み込まれた後の各.gallery-item
s を、クラスを含むページ( https://webhelytervezo.hu/en/ ) とクラスを含むページ( https:/ /webhelytervezo.hu/en/ )。このコードは、メイン ページ (コンテンツは読み込まれていないが、読み込む必要がない場所) でのみ機能します。#gallery-1
#partner
.page-id-202
.page-id-201
編集 3#
コードは次のとおりです。
jQuery(document).ready(function( $ ){
$('.page-id-202 #partner, .page-id-201 #partner').load('https://webhelytervezo.hu/ #gallery-1', function(){
$(".gallery-item").each(function() {
$(this).wrap($("<a/>").attr("href", "http://" + $(".gallery-caption", this).text().trim()));
$("#gallery-1 a").attr('target','_blank');
})
});
$(".gallery-item").each(function() {
$(this).wrap($("<a/>").attr("href", "http://" + $(".gallery-caption", this).text().trim()));
$("#gallery-1 a").attr('target','_blank');
})
});
どうすれば簡単にできますか?