-1

EDIT: I have a RadEditor control and want to build a filter that replaces tag types like <del>...<\del> with <s>...<\s>. See docs.telerik.com/devtools/aspnet-ajax/controls/editor/… where getHtmlContent provides an incoming param a to function with which I want to return the result.

Looking at the answers here... how to change an element type using jquery, how to use this referenced work to work on incoming parameter 'a' of wrapper function 'r' for return by another function. For example, I have...

function replaceTagType(a, b, c) {
   var newContent;

   /* where 'a' is the target content, 'b' is the target tag type (i.e. <b>)
      and 'c' is the new tag type (i.e. <u>).  What to put here that uses
      above referenced work in "how to change an element type using jquery"
      to assign the results to newContent ? */

   return newContent;
}

So if a = "<b>test</b>", resultant var newContent = "<u>test</u>"

Community
  • 1
  • 1
Adam Cox
  • 2,423
  • 1
  • 22
  • 33
  • cant you replace test by test ? – ddw147 Dec 18 '15 at 07:25
  • Parse `a`, apply solution in the linked question and convert the element back to HTML? – Felix Kling Dec 18 '15 at 07:31
  • I think incoming param a is DOM. Context: I have a RadEditor control and want to build a filter that replaced tag types like with . See http://docs.telerik.com/devtools/aspnet-ajax/controls/editor/managing-content/content-filters where getHtmlContent provides the incoming param a to function with which I want to return the result. – Adam Cox Dec 18 '15 at 07:38
  • @FelixKling ok. What does that look like? (thanks) – Adam Cox Dec 18 '15 at 07:44

2 Answers2

0

Try this

  1. find all <b>,
  2. get plain text (winthout html tags) by text() function
  3. get parent element
  4. create new <u> element with text from <b>
  5. replace content of parent element by html() function

Code:

$.parseHTML(a).find(b).each(function(){
    var t = $(this);
    t.parent().html($("<"+c+">").text(t.text()));
});
0

check this

var a = $("div").html(); 
//console.log(a);
a=a.replace('<u>', '<b>');
a=a.replace('</u>', '</b>');
$("div").html(a); 

https://jsfiddle.net/fopuxe57/

ddw147
  • 1,826
  • 2
  • 19
  • 33