Jump to content

Replacing


The Praetorian

Recommended Posts

Okay, I don't know anything about javascript. But I'm using this blog, and I'm trying to use javascript to replace the text in a div. (Which is what the person running the site told me to do.)This is the script.

<script>  var links = document.getElementsByTagName ('div.nublog_title'); for (var l = 0; l < links.length; l++) { str = links[l].innerHTML; if (str.match (/Praetorian's Reading Room/i)) links[l].innerHTML = str.replace (/Praetorian's Reading Room/i, "The Library of Cira Karohn"); } </script>

And here's the link. My blog

Link to comment
Share on other sites

It would be helpful to break the lines after certain syntax in your javascript code. :)Like this:

<script>  var links = document.getElementsByTagName('div.nublog_title');for (l=0; l<links.length; l++){ str = links[l].innerHTML;  if (str.match(/Praetorian's Reading Room/i))    links[l].innerHTML = str.replace(/Praetorian's Reading Room/i, "The Library of Cira Karohn");}</script>

Reads a lot better. But you are free to do it your way :)

Edited by Dan The Prof
Link to comment
Share on other sites

I'll do that, but is there something wrong with the script? Because it doesn't work..

var links = document.getElementsByTagName ('div.nublog_title');
There is not tagname div.nublog_titleyour code will work if you just use div
var links = document.getElementsByTagName ('div');

If you need to access the class then you will need something like getAttribute()

Link to comment
Share on other sites

It still doesn't seem to work that way. Originally the tag was supposed to change the text of a link, so I just changed the tag type to replace (from 'a' to 'div', and then changed the text to be replaced). But that didn't work.Here's the css that I have and am allowed to adjust.

a{color: #000000;text-decoration: underline;}.module_heading{background:#000000;color:#BDB76B;font-family:verdana;font-size:14px;width:250;padding:4px;margin:2px;border:1 #3399FF solid;text-alignment: left;} .module_content{background:#66CC66;color:#000000;font-family:verdana;font-size:12px;width:250;padding:4px;margin:2px;border:1 #3399FF solid;text-alignment: left;} .nublog_title{background:#000000;color:#00CED1;font-family:verdana;font-size:14px;width:550;padding:4px;margin:2px;border:1 #3399FF solid;text-alignment: left;} .nublog_date{background:#696969;color:#00CED1;font-family:verdana;font-size:12px;width:550;padding:4px;margin:2px;border:1 #3399FF solid;text-alignment: left;}.nublog_entry{background:#696969;color:#00CED1;font-family:verdana;font-size:12px;width:550;padding:4px;margin:2px;border:1 #3399FF solid;text-align: left;} body{background: #000000;background-image: url("http://www.tsrealms.com/background.jpg");background-attachment:fixed;}img.background{attachment:fixed;width:100%;height:100%;}

And here's the html straight from the source code. Near as I can tell, this is the html that I'm trying to adjust. Now bear in mind that I do not have access to the html. Only to the css.

<table border=0 cellspacing=0 cellpadding=0 id=nuTable><tr><td valign=top><div class=module_heading>Recently Added</div><div class=module_content></div></td><td valign=top width=100%><div class=nublog_title> Praetorian's Reading Room </div><div class=nublog_date>   </div><div class=nublog_entry><table border=0 class=reading><tr><td><b>Title</td><td><b>Author</td></tr>	</table></div></td></tr></table></div> </td></tr></table> </td></tr></table> </td></tr></table> </td></tr></table></div></div></div></div><title> NuTang.com • Praetorian's Weblog Site  </title>

Link to comment
Share on other sites

This is you javascript that should be added to the page, i haven't touched the css or html and it works.

<script>  onload=function check(){var links = document.getElementsByTagName('div');for (var l = 0; l < links.length; l++) {  str = links[l].innerHTML;  if (str.match (/Praetorian's Reading Room/i))  links[l].innerHTML = str.replace (/Praetorian's Reading Room/i, "The Library of Cira Karohn"); }}</script>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...