Thanks Scott ! Your proposals are an inspiration in doing things better. > > > But even here, there is still something strange. On each click of the > > > div, you're binding another event handler to do the same job. >> >> that's the CENTER OF MY TROUBLE ... >> [...snip...]
> Well, first of all, it's a somewhat strange UI. I certainly wouldn't > want to click for every paragraph; and even if I did, I would think a > "Next" button would be a better place to click than on the paragraph > itself. But that aside, I'm sure it can be done. its just an example for simplicity. > First of all, does the click have to be in the last paragraph itself? > Or could it be in some parent container of the paragraphs? > [...snip...] it's not possible to use the parent, I need the identified paragraph in the ajax-call The real structure is XML as follows: content s a ... /a b ... /b /s s a ... /a /s s a ... a b ... b /s content [a] contains text [b] its translation there might be text ([a] ) without a translation ( [b] ) each text ([a] or/and [b]) can be modified or deleted. Adding new text means to append s a ... /a /s this would be "the next paragraph" in the simplified example. Coming back on my early show() coding, that bothers you (and me). The easiest way to update the content after an AJAX call seemed (to me) to replace ALL content (the old text) in calling Show( old + new text). That's not beautiful but may be useful - especially I could take the same principle in showing "a totally other chapter". Well, I will not do it longer this way. Instead I will append it ... $content.append("<s> ... </s>").children("a").click( function() { AJAX-call }; -> the old content will not be touched and the new one will added and bound to a click handler (as the old one's already have) And now the special case when all content has to be substituted. That matches following code out of your proposal: > var $content = $("#content"); > > function showNextChapter() { > chapter = getNextChapter(); > $content.empty().append("<h2>" + chapter.title + "<\/h1>"); > $content.append(chapter.paragraphs[paragraphIdx]); > } > > function showNextParagraph() { > if (!moreParagraphsForChapter()) { > showNextChapter(); > return; > } > $content.append(getNextParagraph()); a qualitative difference to my Show()-Function is a call on empty() in front of setting new content. This seem to be the solution to my trouble. In other words: I could take my Show()-Function (= RE-SETTING all text + event handlers) IF - that seem to be the point - IF I call the empty() function before. It would not be a beautiful way, I really agree, but it would be a working way without negative side-effects or problems. Can you confirm ? Calling empty() before setting the new content will work around your comment ( >>> But even here, there is still something strange. On each click of the div, you're binding another event handler to do the same job <<< What will I do now ? *) I will take some lessons in Javascript OOP (... the prototype construct ... etc.) *) I will rework my code being more appropriate Javascript OOP *) I will append new paragraphs and give them a click handler (as the old <p>'s already have) *) I will do an empty() call on the container, before I give new content to it. Am I right ? Did I forget or misunderstand something ? Don't hesitate to contradict if you find something wrong ! And thanks once more for your comments and inspirations ! <s type=":-)"> [a type="German"]einen guten Rutsch ins Neue Jahr[/a] [b type="English"]slide well to the New Year[/b] </s> -- fran -- View this message in context: http://old.nabble.com/jQuery-%2B-OOP-%2B-AJAX-tp26945051s27240p26968839.html Sent from the jQuery General Discussion mailing list archive at Nabble.com.