I’m trying to isolate (and then manipulate) quote block formatted in common newsreader and email-client manner.
The HTML:
<p>
Hello there!
<br />
I'm great, how are you?
<br />
<br />
Someone wrote:
<br />
> Greetings,
<br />
> How are you?
</p>
I need to target all the lines that start with >, and hide them as a collapsable block. In the above example everything bellow “Someone wrote:” would then be hidden, saved as a variable and the end result produced by JS would be:
<p>
Hello there!
<br />
I'm great, how are you?
<br />
<br />
Someone wrote:
<br />
<a href="#">Click to expand</a>
</p>
Gmail does the same thing, but it serverside wraps the quotation block in a <div>, due to the specific nature of my project the complete process has to be done by JS alone.
I’m working with the jQuery framework.
Thanks in advance!
I put together an example for you at this pastebin. Here is the code with comments added.
HTML
Script
I changed the link to just a ‘[+]’ to toggle the view but I didn’t bother changing it to ‘[-]’ when the reply is open. I figured the code was getting long enough as it is for this example.
With the new code you posted, I had to make a few changes.
” and the number of these was variable
<a name="" style="color: gray;"/>in the code, but that is not properly formatted HTML… you can’t close an<a>tag this way.New Update:
<BR>instead of<br>so the split wasn’t working. I ended up using$.browser.msieeven though it isn’t recommended. Also, the original script left unopened</div>which is why it broke in IE as well.rplyvariable I used before wasn’t updating between the iterations of the each function, so I moved it’s value into a hidden input tag. I tried making it global, but it just wouldn’t cooperate. It’s probably not the ideal way to do this, so fix/adjust as you desire.Required HTML
Updated Code for IE & new pastbin posting: