Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-21-2012, 11:25 AM   PM User | #1
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
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...
angelali is offline   Reply With Quote
Old 10-23-2012, 03:18 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,393
Thanks: 18
Thanked 351 Times in 350 Posts
sunfighter is on a distinguished road
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>
sunfighter is online now   Reply With Quote
Old 10-23-2012, 05:02 PM   PM User | #3
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
well i got my answer, you should do it with "contenteditable" feature in HTML5, then use document.execCommand in JavaScript!
angelali is offline   Reply With Quote
Old 10-23-2012, 05:43 PM   PM User | #4
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,393
Thanks: 18
Thanked 351 Times in 350 Posts
sunfighter is on a distinguished road
Correct me if I'm wrong but doesn't document.execCommand ONLY work in IE and is therefore not a real world solution?
sunfighter is online now   Reply With Quote
Old 10-23-2012, 05:49 PM   PM User | #5
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
Nope it works for all, search it... The only difference is that it does not work the same as other browsers..
angelali is offline   Reply With Quote
Old 10-23-2012, 06:02 PM   PM User | #6
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,393
Thanks: 18
Thanked 351 Times in 350 Posts
sunfighter is on a distinguished road
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?
sunfighter is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:59 AM.


Advertisement
Log in to turn off these ads.