1

Possible Duplicate:
Given an ID, find and replace the last sentence with a span wrapper

Give a DIV with a block of text with sentences, meaning a period.

How does one use the JQUERY text nodes to find the last sentence and wrap just the last sentence in a SPAN tag?

Thanks

Community
  • 1
  • 1
WozPoz
  • 992
  • 2
  • 15
  • 29
  • 1
    You mean like this question that you asked 2 days ago? http://stackoverflow.com/questions/3278076/given-an-id-find-and-replace-the-last-sentence-with-a-span-wrapper/ – user113716 Jul 22 '10 at 01:22
  • @Patrick, good question. Very similar but I learned that answer was flawed as it did not use text nodes and modified the DOM. – WozPoz Jul 22 '10 at 01:23
  • 2
    If you want to wrap the sentence with `` tags, you'll be modifying the DOM. Text nodes don't offer you anything special. They're merely the type of node (type 3) representing the text between other nodes (type 1). Unless the sentence in question happens to fall neatly in between a couple of type 1 nodes, they won't be of any help to you. – user113716 Jul 22 '10 at 01:26
  • I've seen solutions like this that update with a and do not mess with the DOM, meaning the mouse cursor doesn't get effected and the user can continue typing while this goes on. So I'm not following? http://refactormycode.com/codes/341-jquery-all-descendent-text-nodes-within-a-node#refactor_12159 – WozPoz Jul 22 '10 at 01:27
  • 2
    Let's say you have a `
    ` with a bunch of content. The content is `

    ` elements with text. But in between the various `

    ` elements, there's additional text. That additional text is represented by a "text node". It's like a container when there isn't a container specified. So if you want to wrap an entire text node, that is easy. But text nodes are not broken down by sentence. So one text node, could have 100 sentences. There is no further breakdown within the node.

    – user113716 Jul 22 '10 at 01:34
  • That's very helpful... Would it be possible to take a text node, wrap all sentences in a and then use that to find the last text node, do the span wrap, and then remove the madeuptag that was used for an index? – WozPoz Jul 22 '10 at 01:36
  • 1
    You mean wrap each sentence in a ``? If so, then you might as well just wrap them in `` tags. It is no longer a text node if you wrap it with any type of tag. And you'll have IE issues with some arbitrary made up tag. If you wrap each sentence with a ``, you're essentially doing the same thing as the solutions to your previous question, except for every sentence. Is the HTML layout basically the same as your last question? If so, there are no text nodes. They were all `

    ` tags with text content.

    – user113716 Jul 22 '10 at 01:47
  • Maybe a better solution would be to use the other solution but find a way to put the mouse cursor back to the end of the text after the function runs? What do you think about that idea? in order to solve the goal if allowing this func to run while the users typing and to allow the user to keep typing after it runs, without requiring their mouse? – WozPoz Jul 22 '10 at 01:54
  • More accurately, the text inside an element is a text node. – user113716 Jul 22 '10 at 01:55
  • Are you talking about text inputs? Or elements that are contentEditable? I don't understand what you mean about the cursor. – user113716 Jul 22 '10 at 01:56

0 Answers0