No al cierre de webs
ShareCode
Permalink: http://www.treeweb.es/u/974/ 01/02/2011

ShareCode

1 2 function clearHTML(text, cb) {3  if (cb == undefined)4  cb = clearHTML_default_cb;5  6  var div = document.createElement('div');7  div.innerHTML = text;8  return clearHTML_recursive(div.childNodes, cb, 0);9 }10 11 12 13 14 function clearHTML_recursive(cn, cb, level) {15  var result = '';16  17  for (i=0; i<cn.length; i++) {18  var node = cn[i];19  var nt = node.nodeType;20  if (nt == 3) {21  result += node.nodeValue;22  } else if (nt == 1) {23  var clear_inner = clearHTML_recursive(24  if (clearHTML_default_cb(node)) {25  // Sí pasa el filtro26  node.innerHTML = clearHTML_re27  }28  //if (cb(text.innerHTML, cb, level+1) {}29  }30  }31  32  return result;33 }34 35 function clearHTML_default_cb(o) {36  return true;37 }38 39 function inspect(o) {40  var s = '';41  for (k in o) {42  s += k+' = '+o[k]+'\n';43  }44  alert(s);45 }46 47 var html = 'a<div>hola<br>una <b>fbrase</b> <i>con</i> formato</div>b'48 49 alert(clearHTML(html));
Enlace
El enlace para compartir es: