2016-07-08 12 views
0

私はWYSIWYGモードでページを作成できるVisual Composerプラグインを使用してWordpressサイトhttp://gambit.co/testを持っています。それによって作成されたすべてのコンテンツはajaxとjavascriptで読み込まれます。私は素敵なメディアグリッドセクションを持っていますが、四角形への特定のリンクを割り当てることはできません。彼らはすべて彼らのイメージに関連したミニチュアです。動的に作成されたリンクのhrefを変更します。

私はjQueryの

jQuery(document).ready(function($) { 
$("a[href='http://gambit.co/test/wp-content/uploads/2016/07/600_wynajem.jpg']").attr('href', 'http://www.google.com/'); 

}); 

とのリンクを交換しようとしましたが、何のHTMLコンテンツが存在しないため、スクリプトの実行時に私も仕事をdoesntの。 BODYタグを閉じる直前にスクリプトをページの一番下に移動しましたが、idは動作しませんでした。 .attrと.propの両方で試しました。私は何をすべきか?

+0

'コンテンツは、AJAXやJavaScriptがロードされている:あなたのような何かを書くことができます。このように

.ajax';それとも別の何か? – vijayP

答えて

0

DOMNodeInsertedをご覧ください。 ; `それは` $を使用して、あなたが書かれては、コードによってロードされたばかりという意味ではない

// as soon as a new anchor tag is added to the dom and 
 
// the href value of this element is...... 
 
$(document).on('DOMNodeInserted', 'a[href="http://gambit.co/test/wp-content/uploads/2016/07/600_wynajem.jpg"]', function(e) { 
 
    this.href = 'http://www.google.com/'; 
 
    
 
    this.textContent = 'http://www.google.com/'; 
 
}); 
 

 

 
$(function() { 
 
    $('#btn').on('click', function(e) { 
 
    $('body').append('<a href="http://gambit.co/test/wp-content/uploads/2016/07/600_wynajem.jpg">My sample</a>'); 
 
    }) 
 
});
<script src="https://code.jquery.com/jquery-1.12.1.min.js"></script> 
 

 
<button id="btn">Add link</button>

関連する問題