how to remove the class attribute from the selected text range?

advertisements

i need to remove class attribute from the selected text(selected text means user will select some range of text by mouse). if the selected text has the class='ansspans', then we need to remove that class for that particular selected text. ( i am using this in gridview, so many rows will be there, so i need to remove class for that particular selected text)

 <span id="sss_ctl00_ctl06_lblAnswerText" class="Label">
      <span>ssss</span><span class="ansspans">assignment</span>submission
 </span>

  1. if User Selects assignment from the page, which already has class='anspans', then if he click button(to reset highlighted marking), then for that particular selected text, we should remove the class attribute. after clicking the button.

Output

  <span id="sss_ctl00_ctl06_lblAnswerText" class="Label">
       <span>ssss</span><span>assignment</span>submission
 </span>

here why i am doing this,

  1. Basically user will select some word and mark some word. (marking and highlighting is all done, n working fine ) ( imagine he selects 3 words)
  2. Now user wants to remove the one of the highlighted word, then he selects the word, then click reset button. then for that selected text, class attribute will be removed. which i am facing problem.

Update : Even i tried one of my friends solution like this. JSfiddle - still not working for my page.


A Rangy-specific version of this is solved on the Rangy forum. Code is quite lengthy so not reproduced here. http://groups.google.com/group/rangy/browse_thread/thread/5738cf7bc32c607a

Demo: http://jsfiddle.net/URms2/