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.

1

1 Answer 1

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>

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.