3

How to use an hidden character in text string using JavaScript.There is one text string which i read and writes back with the hidden character in it (so rewritten text looks same as the original text though it comtains the hidden character), so that next time i read the text i can come to know that this text is aleady read as it contains the hidden character

Eg)

< html>
< body>
< div>
This is a simple text
< /div>
< /body>
< /html>

I am trying to parse the div and extract the contents of the div, and insert an hidden character to the text and rewrite the text to the div again using JavaScript.

I just want to know which hidden character should i use to insert into the text ? How to write the hidden character into the text ?

AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
user105165
  • 93
  • 1
  • 8
  • 1
    This seems to be a weird requirement. But what do you want to something like this for? – Kirtan May 20 '09 at 11:03
  • By the way you can insert anything between less than & greater than brackets to make it invisible . . . – Kirtan May 20 '09 at 11:04

2 Answers2

3

Since you are using javascript why don't you just add a property to the div:-

var divs = document.getElementByTagName("div");
for (var i = 0, length = divs.length; i < length; i++)
{
    if (!divs[i].hasBeenRead)
    {       
         fnReadDiv(divs[i]);
         divs[i].hasBeenRead = true;
    }
}
AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
0

To answer the question, keep an array of the divs that have been traversed:

var divsChecked = [];
//code that looks at the div
divsChecked.push(div.getAttribute('id'));

However I think that the method that you are using to traverse the items may not be correct with libraries like jQuery you could loop over each div in turn thereby you shouldn't ever see the same div twice unless you run the loop twice.

Grant Wagner
  • 25,263
  • 7
  • 54
  • 64
UnkwnTech
  • 88,102
  • 65
  • 184
  • 229
  • You're looking for "= []" and ".push()" – Crescent Fresh May 20 '09 at 13:43
  • I want to manupulate the parsed string by adding the hidden character so that next time i check for the string i will know that it has been handled earlier. I just got the reference of the ascii null character, but not sure how to implement them – user105165 May 21 '09 at 06:12
  • I still think that your going about this wrong, adding text is not the optimal way of going about it. I would use AnthonyWJones' answer or just add some text like to it this is an HTML comment and will not be shown to the user. – UnkwnTech May 21 '09 at 06:28