Guys i have a html string like below;
<html>
<head><title></title></head>
<body>i wanna remove <span name="Note">this</span> tag</body>
</html>
i use this javascript code:
NSString *str = @"function f(){
var nodes = document.getElementsByName('Note');
alert(nodes.length); // it returns node count correctly
for(var i = nodes.length - 1;i >= 0;i--){
var node = nodes[i];
if (node){
node.parentNode.removeChild(node);
}
}
}f();";
[UIWebView stringByEvaluatingJavaScriptFromString:str];
result is :
<html>
<head><title></title></head>
<body>i wanna remove tag</body>
</html>
how can i remove only tag?
You could try:
but this will cause weird results if you got nested tags like
<span class="Note">foo<span>bar</span></span>if remove the class is enough guess you could do something like this:Edit: