Ollifi Posted June 4, 2011 Share Posted June 4, 2011 Hello. how could I search all anchors <a name="****A****">****B****</a> And then edit the text part B. Example, this <a name="1202">Hello!</a> would replace <a name="1202">Hello! <small>ID#1202</small></a> This is coming a greasemonkey script. Hopefully you can help. thank you very much. EDIT: I coded this: (bookmarklet test) javascript:function(){for(i=0;i<document.links.length;i++){if(document.links[i].name){document.links[i].innerHTML = "Test "+document.links[i].name+"";}};}(); but it didn´t work. Link to comment https://forums.phpfreaks.com/topic/238379-search-all-anchors-and-then-edit-their-cotent/ Share on other sites More sharing options...
Adam Posted June 4, 2011 Share Posted June 4, 2011 You can use the getElementsByTagName method: var anchors = document.getElementsByTagName('a'); var length = anchors.length; for (i=0; i<length; i++) { // Access link text through: // anchors[i].text } Link to comment https://forums.phpfreaks.com/topic/238379-search-all-anchors-and-then-edit-their-cotent/#findComment-1225255 Share on other sites More sharing options...
Ollifi Posted June 5, 2011 Author Share Posted June 5, 2011 Hello, thank you for it. But it still doesnt work javascript:(function () {var anchors = document.getElementsByTagName('a');var length = anchors.length;for (i=0; i<length; i++){if(anchors[i].name){anchors[i].text="Testi...";}}(); Link to comment https://forums.phpfreaks.com/topic/238379-search-all-anchors-and-then-edit-their-cotent/#findComment-1225374 Share on other sites More sharing options...
Ollifi Posted June 5, 2011 Author Share Posted June 5, 2011 I got it fixed: javascript:(function () {var anchors = document.getElementsByTagName('a');var length = anchors.length;for (i=0; i<length; i++){if(anchors[i].name){var vanha=anchors[i].innerHTML;anchors[i].innerHTML=""+vanha+" <span style='font-size:10px;color:black'><a href='javascript:prompt(\"URL:\", \""+location.href+"~no.paging#"+anchors[i].name+"\");'>ID</a></span>";}}})(); Link to comment https://forums.phpfreaks.com/topic/238379-search-all-anchors-and-then-edit-their-cotent/#findComment-1225402 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.