Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post

    search and replace in string

    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

    Code:
    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...

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •