Function to clear html

Asked

Viewed 433 times

1

How to make a function that cleans HTML? I have a field that comes from a WS and needs, before displaying on the page, to clear HTML.

They sent me this:

String result = Regex.Replace(htmlDocument, @"<[^>]*>", String.Empty);

I need to put this code in a jquery function, right here and the this.ShortDescription is the guy I want to clean up. How I do?

str += '<p>' + this.ShortDescription + '</p>';

The above code is part of a jQuery function.

  • 1

    How to clear html?

  • @pnet, for example your input is <p><strong>algum texto.....</strong></p> and you want some function to just return algum texto that’s it?

2 answers

3

In javascript you can use:

document.body.innerHTML = '';
  • I have difficulty with jquery and javascript. I have a jquery that takes a WS text, like this: str = str + this.Description; Then I download the str variable on the page and it is mounted everything. This is working. As I now remove the html tags from Description, as last example?

  • 1

    yes, but like so Description?

  • is the field I picked up in the WS jquery so: this. Description; this field is the one that has the texts I put on the page. How I remove the tags from it?

  • @pnet tries this.Description.innerHTML = '';

  • It didn’t work. It was Undefined =

  • @pnet tries to post more parts of your code so we can better understand your problem...

Show 1 more comment

0

I use the following Vb.net code:

Public Function limpaHTML_Recursiva(ByVal sTexto As String, ByVal j As Integer) As String
    If j = 0 Then
        Return sTexto
    End If
    Dim i As Integer = 0
    i = InStr(sTexto, "<")
    j = InStr(sTexto, ">")
    If i > 0 Then
        i -= 1
    End If
    sTexto = Left(sTexto, i) & Right(sTexto, sTexto.Length - j)
    Return (limpaHTML_Recursiva(sTexto, j))
End Function

Flame with :sTexto = limpaHTML_Recursiva(sTexto, 1)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.