CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript frameworks (http://www.codingforums.com/forumdisplay.php?f=62)
-   -   How to make a text bold by highlighting? (http://www.codingforums.com/showthread.php?t=278446)

angelali 10-21-2012 11:25 AM

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...

sunfighter 10-23-2012 03:18 PM

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">
::-moz-selection{
background:#C1EEFB ;color: red;}
::selection{
background:#C1EEFB; color: red;
}
</style>


angelali 10-23-2012 05:02 PM

well i got my answer, you should do it with "contenteditable" feature in HTML5, then use document.execCommand in JavaScript!

sunfighter 10-23-2012 05:43 PM

Correct me if I'm wrong but doesn't document.execCommand ONLY work in IE and is therefore not a real world solution?

angelali 10-23-2012 05:49 PM

Nope it works for all, search it... The only difference is that it does not work the same as other browsers..

sunfighter 10-23-2012 06:02 PM

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.