0

I want to add an attribute to a text node so that I can uniquely identify it. Is there a way to do this in javascript?

user730569
  • 3,940
  • 9
  • 42
  • 68
  • You could identify it by a) logging a reference to it in a var; b) noting its index amongst its siblings (granted b is not an option if you're moving elements around). Otherwise, as @Matt Ball says in his answer. – Mitya Jul 24 '12 at 17:48

1 Answers1

3

Not in a safe, simple, cross-browser way. Only tags have attributes, and text nodes are not tags.
Wrap it in a <span> and use an ID on the span.

Matt Ball
  • 354,903
  • 100
  • 647
  • 710