0

I need to make a text editor for my site. Here are a few questions that I have:

  1. How can I retrieve the row selected in the text area using JavaScript?
  2. How can I style the first line of the text without styling all rows the same?

Here is an example of what I need:

<textarea>
    <span class='center_align'>Hello world</span>
    <span class='left_align'>This is a nice paragraph aligned to the left.</span>
</textarea>

I know <textarea> reads HTML into its input, but how would I go about to style this?

Chris Forrence
  • 10,042
  • 11
  • 48
  • 64
THE AMAZING
  • 1,496
  • 2
  • 16
  • 38
  • 1
    Look up `contenteditable` – Musa Aug 21 '13 at 23:51
  • 1
    If these are your requirements, then you're looking at something more complex than just a textarea unfortunately; you cannot style a textarea in the manner you require. – Adrian Wragg Aug 21 '13 at 23:52
  • Hmm i just looked into someone elses source code which is extremely long -.- and crypted.. (IPB) .. And they do it using iframe. Is there another reliable way? – THE AMAZING Aug 21 '13 at 23:57

1 Answers1

2

Sounds like you need a Rich Text Editor: try TinyMCE (as used by WordPress): http://www.tinymce.com/

Alfie
  • 2,341
  • 2
  • 28
  • 45
  • Yees that is exactly what i need, but i need to create the editor myself. i cannot use 3rd party – THE AMAZING Aug 22 '13 at 00:16
  • If your concerns are regarding inclusion within a commercial project, TinyMCE is licensed under LGPL, see this post for more info: http://stackoverflow.com/questions/2145216/gnu-lesser-gpl-application-sell Otherwise, if you must still do it yourself, my approach would be to use a regular `div` to present the styled output, combined with a lot of JavaScript to make the div editable and act like a typical textarea – Alfie Aug 22 '13 at 00:24
  • you can't do it by using only a textarea. If you see the html markup of TinyMCE, the content you are adding is not only a text but a html markup inside an iframe. use firebug and see how it's working... – Ryxle Aug 22 '13 at 05:20