Suppose the user in the Html editor typed some text (with pictures, invented and understood by the browser tags, etc.).

I have this html. How to literally remove all these tags and get only the text? Those. remove this formatting and all unnecessary (pictures too) except for text.

What can be used to implement is written in tags.

    3 answers 3

    See example

    $('#content').text(); 
    • <div id = "content"> <div> AJDJKSH </ div> 123 </ div> You will get back: <div> AJDJKSH </ div> 123 And I need to get: AJDJKSH123 - megacoder
    • one
      Have you ever checked? See your example - Deonis
    • I apologize, did not look :) I confused with .html (); Thank! - megacoder

    jQuery:

     var text = '<a href="someurl">Hello world</a>some text<img src="someimage">'; alert($(text).text()); 
    • see first comment on @Deonis - megacoder reply

    Well on jQuery you can do it like this:

     <script> $(document).ready(function(){ alert($("#n1").text()); // вывод: "12111" }); </script> <div id="n1"> <p>1</p><p>2</p><p>1</p><p>1</p><p>1</p> </div> 
    • ))) Yeah ... Now they will tell you that it doesn’t work =) And I, and FLK, and now you - about the same sing. - Deonis
    • In the sense of not working? - AseN
    • okay) stupid question author =) - AseN
    • You can forget. TC just did not pay attention. - Deonis