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?

1
  • 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. Commented Jul 24, 2012 at 17:48

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.