6

When making a simple WYSIWYG editor with JavaScript for a textarea I can check the current status of a button (Bold, Italic, Underlined etc) like that:

document.queryCommandState("bold")

But if I'd like to see if selected text has a link attached, how could I do that (or is it a longer process?). The same query (or queryCommandValue) with "CreateLink" does not seem work.

Allan
  • 201
  • 4
  • 12

1 Answers1

3

Since document.queryCommandState("CreateLink") (see this article) doesn't seem to work, you'll have to get the selection and the DOM element for it. If that DOM element is an a element, you have the link. If you allow to style the text of a link, you must look further up in the element tree.

Community
  • 1
  • 1
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • 1
    As I said before, that does not work. It just gives me an Exception error "Component returned failure code..". – Allan Aug 26 '09 at 12:14