I am trying to convert the following html
<div class="bbQuote">
<div class="quoteAuthor">Joe Block</div>
<div class="quoteContent">This is the first message<br>
<div class="bbQuote">
<div class="quoteAuthor">Jane Doe</div>
<div class="quoteContent">This is the second message</div>
</div>
</div>
</div>
to the following bbCode
[quote=Joe Block]
This is the first message
[quote=Jane Doe]
This is the second message
[/quote]
[/quote]
How can I do this using jQuery?
PS: Nested HTML can have zero or more children
Here's a very basic example:
Fiddle
Limitations:
<b>
,<i>
, anchor tags etc);I'd use Ajax to fetch the actual post content from the DB or use a proper jQuery bbCode parsing library.