...

View Full Version : search and replace in string



homerUK
06-03-2004, 04:58 PM
Hey,

I have a string which might look like the following

<table style='border:1px solid black'><tr><td>&nbsp;</td></tr></table>

I need to search through it and remove the style attribute...

here's the code I have been trying



theHTML = "<table style='border:1px dashed #C0C0C0'><tr><td>&nbsp;</td></tr></table>";

var allForms = theHTML.getElementsByTagName("TD");
for (a=0; a < allForms.length; a++) {
allForms[a].removeAttribute("style")
}


but it doesnt seem to work...

any ideas on how I can search the string and remove the style attribute? thanks for any help...

liorean
06-03-2004, 05:29 PM
You can't use the DOM on a string. The DOM wortks on constructs in the document, however. Is this natively a string or have you gotten it from the document? If the former, you should look into a regular expressions based solution, if the latter, you could just retarget theHTML to point to the element in question within the document.

homerUK
06-03-2004, 05:32 PM
thanks for the reply.. it's taken from the document, but I do not want to actually perform the removal of the borders to the main document.

THe main doc has the borders, and I open a new window which I then want the same contents as the main doc, but with out the borders...

...is that not very clear?! umf!

think the reg exp might be the only way?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum