2016-07-08 123 views
0

我使用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内容的脚本运行时。我将脚本移到了页面的底部,就在关闭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>