javascript - document.ready and window.load not working -


i'm trying run jquery on page getting content pulled in dynamically , creating links can't work. code simple:

$(".link a[href*='xyz'][href$='pdf']").text('change link text'); 

i have put inside document.ready , window.load , neither made difference. i've ran on console in inspector , works fine on live page doesn't have affect. added console.log code , can see code being triggered can't figure out how make work.

any ideas?

you need mutationobserver, here in snippet have used settimeout simulate anchor added dynamically.

var mutationobserver = window.mutationobserver || window.webkitmutationobserver || window.mozmutationobserver;    var element = document.queryselector('.link');  settimeout(function() {    $(".link").append('<a class="mylink" href=".pdf">yahoooooo</a>');    $(".link").append('<a class="mylink" href=".xyz">yahoooooo</a>');  }, 5000)    var observer = new mutationobserver(function(mutations) {    mutations.foreach(function(mutation) {      if (mutation.type == "childlist") {        console.log("nodes inserted changed")        $(".link a[href$='pdf'], .link a[href*='xyz']").text('change link text');      }    });  });    observer.observe(element, {    childlist: true //configure listen attribute changes  });
.mylink {    display: block;    width: 200px;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div class="link"></div>


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -