views:

54

answers:

1

looking at this issue on stackoverflow, i got going in the right direction to what i'm looking for: http://stackoverflow.com/questions/652917/in-jquery-want-to-remove-all-html-inside-of-a-div

i have a textarea similar to the following:

<textarea id="inputPane" cols="80" rows="40" class="pane" style="height:300px;">
<table><tr><td>
 <b>Since your service bureau</b>, xxx is not certified 
 by our company for xyz, your company will need to complete 
 more testing as part of the process.
</td></tr></table>
</textarea> 

using this code from the url listed above, i'm able to remove all whitespace apparently, but am unable to remove the actual html tags: etc...

jQuery.fn.stripTags = function() 
{ return this.replaceWith( this.html().replace(/<\/?[^>]+>/gi, '') ); };

my question on the above code is this: what is this part saying?

/<\/?[^>]+>/gi

i think it reads: remove this character <, and remove this character > and replace with nothing.

Although this is not what it is doing in my code. It seems to strip all the whitespace from the DIV i put it on.

What is the gi part? And would you have a good solution to remove HTML tags from a wmd-editor textarea when the html displayed is coming from a database?

A: 

I use the following script to remove html tags from a string-

 function removeHTMLTags(htmlString)
 {
    if(htmlString)
    {
      var mydiv = document.createElement("div");
       mydiv.innerHTML = htmlString;

        if (document.all) // IE Stuff
        {
            return mydiv.innerText;
        }   
        else // Mozilla does not work with innerText
        {
            return mydiv.textContent;
        }                           
    }
 }  

not exactly sure but i think /gi part indicates global replace like in string.replace in javascript

Vinay B R