2

I have following html that is contained in my webpage.

<div id="flashmessage" class="ok">
     <a class="ico-close">x</a>
     MY TEXT HERE
</div>

How to extract 'MY TEXT HERE' from this html using jquery?

Note: I intend to convert this flashmessage to fancybox popup.

Syed
  • 891
  • 2
  • 8
  • 29

1 Answers1

0

Just clone the div which contains text and remove all its children and then get the text. Snippet below:

$(document).ready(function(){
    var text=$("#flashmessage").clone().children().remove().end().text();
    $(".result").text(text);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="flashmessage" class="ok">
     <a class="ico-close">x</a>
     MY TEXT HERE
</div>

<div class="result"></div>
Guruprasad J Rao
  • 29,410
  • 14
  • 101
  • 200