Skip to content

Instantly share code, notes, and snippets.

@arbaouimehdi
Created April 25, 2014 21:33
Show Gist options
  • Save arbaouimehdi/11304080 to your computer and use it in GitHub Desktop.
Save arbaouimehdi/11304080 to your computer and use it in GitHub Desktop.
It is very simple to get content inside DIVs or inside others tags with jQuery, however, the complexity come when we try to get a particular text between two HTML tags, here is an example of solution:
<div class="parent">
<div class="first">first</div>
<div class="child1">child1</div>
Paragraph 1
<br>
Paragraph 2
<br/>
Paragraph 3
<div class="child2">child2</div>
<div class="child3">child3</div>
Last Content
<br/>
Last Content 2
<br/>
Last Content 3
<div class="last">last</div>
</div>
var appendSt = $('.child3').after('code:'),
content = $('.parent').clone().children().remove().end().text(),
reg = content.replace(/code:([^xyz]+)/, '');
alert(reg);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment