jquery - Opening links in a new tab with javascript stops working -


i have code on tumblr blog makes links in "notes" div open in new tab — works fine once click "show more notes" (which loads more links), stops working on links. here code.

<script type="text/javascript"> $(function(){   $("#notes a").attr("target","_blank"); }); </script>  

here tumblr says on issue: "notes paginated ajax. if theme needs manipulate notes markup or dom nodes, can add javascript callback fires when new page of notes loaded or inserted"

tumblrnotesloaded(notes_html) "if javascript function defined, triggered when new page of notes loaded , ready inserted. if function returns false, block notes being inserted."

tumblrnotesinserted() "if javascript function defined, triggered after new page of notes has been inserted dom."

the newly loaded links wont have target set _blank ... should do, when you've loaded new links execute

$("#notes a").attr("target","_blank");  

again - you've shown no code regarding loading of these links, that's best can do

edit: looked @ page - think should trick

this.style.display = 'none'; document.getelementbyid('notes_loading_121152690941').style.display = 'block'; if (window.activexobject) var tumblrreq = new activexobject('microsoft.xmlhttp'); else if (window.xmlhttprequest) var tumblrreq = new xmlhttprequest(); else return false; tumblrreq.onreadystatechange = function() {     if (tumblrreq.readystate == 4) {         var notes_html = tumblrreq.responsetext.split('<!-- start ' + 'notes -->')[1].split('<!-- end ' + 'notes -->')[0];         if (window.tumblrnotesloaded)             if (tumblrnotesloaded(notes_html) == false) return;         var more_notes_link = document.getelementbyid('more_notes_121152690941');         var notes = more_notes_link.parentnode;         notes.removechild(more_notes_link);         notes.innerhtml += notes_html;         if (window.tumblrnotesinserted) tumblrnotesinserted(notes_html);         // ************************************************         $("#notes a").attr("target","_blank");         // ************************************************     } }; tumblrreq.open('get', '/notes/121152690941/lhtxynztk?from_c=1433902641', true); tumblrreq.send(); return false; 

the added line surrounded // ************************************************


Comments