I’m creating a quoting system within a custom bulletin board.
What I need to do is to copy the contents of one div, but place it in a text-area with additional elements.
Could I use jQuery in assisting me to do this?
How would I do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Manipulate string and then copy
This is probably what you’re after:
Then you can easily manipulate your
textareacontent at your own will. This will copy the wholeDIVsub-tree (including all elements) not just textual content. But you have to be aware that DIV’s content becomes a string.Manipulate HTML elements and then copy
If you’d like to manipulate HTML elements then do it this way:
Using
.text()or.html()If you’d only need to use textual content then use
.text()instead.html(). Example:What each of these returns:
Wrapping content in a new element
If you’d like to wrap the whole content inside a new element and then copy (this would be something common for a forum post) do it this way:
Why do we have to wrap it twice? Because
.html()only returns inner HTML of an element. So if we want to return wrapped content as well, we have to wrap it again and then display inner HTML of the newly wrap element. That’s the only reason why double wrapping is required.JSFiddle examples
[quote]and[/quote]: click here<quote>element: click here