SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast szigeti's Avatar
    Join Date
    May 2005
    Location
    Hungary
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to work only with CDATA in DOM?

    I have to create a JS function which guarantees that there can be no text lines with only one word in them. This basically means that I have to replace the space between the last two words in every sentence to a non-breaking one with a simple regular expression.

    To ensure that no tags would be altered (e.g. to prevent modifying text in alt or title attributes) the final regular expression should be quite complex.

    But if there would be a way to select only the CDATA section of DOM in JavaScript, my task would be much simpler.

    Is there a way to find CDATA in DOM with JavaScript? How would you do that?
    Eat healthy,
    Exercise daily,
    Die anyway.

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IIRC anything inside the script tags are treated as text when looked at from javascript. Best thing you can do is to use regex to get the code from inside the cdata tags.

    This regex will do that:

    Code:
    //<!\[CDATA\[([^&#172;]+)//\]\]\>



Bookmarks

Posting Permissions

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