how to get currently selected tag in editor in WYSIWYG mode

2 posts, 0 answers
  1. Uma
    Uma avatar
    18 posts
    Member since:
    Jan 2012

    Posted 31 Jan 2012 Link to this post

    Hi,

    I need to get the currently selected tag.
    So, i am using  editor.getSelectedElement();

    in my editor has code in html like
    <subelement id="717" type="complementary"><tag type="open" text="complementary" elem-tag="subelement">|</tag><p><tag type="open" text="p" elem-tag="p">|</tag>
           
     
          An increasing amount of information on complementary and alternative medicine is becoming available. The scope of the BNF is restricted to the discussion of conventional medicines but reference is made to complementary treatments if they affect conventional therapy (e.g. interactions with St John's wort—see Appendix 1). Further information on herbal medicines is available at
                
    the design mode content looks like below.
    complementary-and-alternative-medicine|
    p| An increasing amount of information on complementary and alternative medicine is becoming available. The scope of the BNF is restricted to the discussion of conventional medicines but reference is made to complementary treatments if they affect conventional therapy (e.g. interactions with St John's wort—see Appendix 1). Further information on herbal medicines is available at XRef : http://www.mhra.gov.uk| www.mhra.gov.uk |Xref : http://www.mhra.gov.uk . |p
    |complementary-and-alternative-medicine


    when the user right cliks with in any of this tag, i need to get the selected tag in editor.

    so, iam using  editor.getSelectedElement();

    the tag format assigned in editor like'
    <tag1><tag2><p>text</p></tag2><tag1>

    tag1 is click, the getselectedelemat return the <p> tag always.

    because the <p> is the editable tag, which contain the text.

    but the user selected the not editable tag, that is the root tag of <p> tag.

    How to get the exact tag that is selected in editor.

    Thanks,
    Uma
  2. Rumen
    Admin
    Rumen avatar
    14351 posts

    Posted 31 Jan 2012 Link to this post

    Hello,

    You should note that RadEditor is not XML editor and it does not support XML tags, because the browser's rich text engine does not recognize and render them. In addition, in IE the custom tags should have namespaces as explained in this article: Using Custom Tags in Internet Explorer.

    My suggestion is to try to get a reference to the selected node using the browser's text range methods and see whether this will work for your custom scenario. You can create a Range in RadEditor's content area using the following code:

    var currentRange = editor.getSelection().getRange(); 
    
    
    Aditional information regarding MS TextRange and W3C Range objects is available in the following articles:

    http://www.wrox.com/WileyCDA/Section/JavaScript-DOM-Ranges-Page-2.id-292302.html
    http://www.quirksmode.org/dom/range_intro.html
    http://msdn.microsoft.com/en-us/library/ms535872%28VS.85%29.aspx

    Note that this is a custom functionality, which is not offered by RadEditor out-of-the box and we do not support it.

    Kind regards,
    Rumen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top