I need to get all of the text contained between a specific div. In the following example I want to get everything between the div with class name “st” :
<div class="title">This is a title</div>
<div class="st">Some example <em>text</em> here.</div>
<div class="footer">Footer text</div>
So the result would be
Some example <em>text</em> here.
or even just
Some example text here.
Does anyone know how to accomplish this?
Server-side in PHP
A very basic way would be something like this:
Then iterate the
$matchobject. However, this could return bad data if your.stDIV has another DIV inside it.A more proper way would be:
Client-side
If you’re using jQuery, it would be easy like this:
or
If you’re using plain JavaScript, it would be a little complicated cause you’ll have to check all DIV elements until you find the one with your desired CSS class: