![]() |
How to make a text bold by highlighting?
Hello, I am making a small application in JQuery. I want to know, how to make a text bold by highlighting it? For example, like those online text editors or WYSIWYG textarea?
Suppose I havea button, once clicked on it, it will write "<strong></strong> but I want that when the user is selecting or highlight the sentence or word with mouse, then click on the button, it apply the Bold effect... |
I have played with this for a couple of days now. In order to play with styles we need to use the ::selection selector in css3 and that can only change the color, background, cursor, and outline styles.
This will change colors, but not font-weight. Code:
<style type="text/css"> |
well i got my answer, you should do it with "contenteditable" feature in HTML5, then use document.execCommand in JavaScript!
|
Correct me if I'm wrong but doesn't document.execCommand ONLY work in IE and is therefore not a real world solution?
|
Nope it works for all, search it... The only difference is that it does not work the same as other browsers..
|
OK I found it at https://developer.mozilla.org/en-US/...uting_Commands
But I am having one hell of a time trying to get it to work. I'm using FF. Could you give us a small snipit of code to bold selected text? |
| All times are GMT +1. The time now is 08:58 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.