473,395 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Static text highlighting -- can it be done?

I'm trying to write an application to demonstrate to a friend how to
highlight text in javascript, only problem is he wants it to be on divs
only.

So say for example you have a page, and you select some text in the div
(this is static text, not a form or anything) and you click "highlight"
is there a way to wrap style tags around that highlighted text using
javascript, without refreshing the page?

thanks.

Jan 6 '07 #1
1 1402
bryan wrote:
I'm trying to write an application to demonstrate to a friend how to
highlight text in javascript, only problem is he wants it to be on divs
only.

So say for example you have a page, and you select some text in the div
(this is static text, not a form or anything) and you click "highlight"
is there a way to wrap style tags around that highlighted text using
javascript, without refreshing the page?

thanks.

Yes it is possible. Though it's a bit of work so I doubt if people are
going to fall all over-themselves to provide you with the code you want.
But yes -- check out...

http://www.quirksmode.org/js/selected.html for how to get the selected text.

Then look into the innerHTML reference, and then look into javascript
replace.

Basically the flow will go.
User clicks button->
Get the selected text->
Save the original division.innerHTML->
run replace on innerHTML to add your tags....

Good luck.

--
http://www.hunlock.com -- Musings in Javascript, CSS.
$FA
Jan 6 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

467
by: mike420 | last post by:
THE GOOD: 1. pickle 2. simplicity and uniformity 3. big library (bigger would be even better) THE BAD:
2
by: Srinath Avadhanula | last post by:
Hello, Sorry to be bringing up what seems to be a somewhat beaten up topic... This is what I wanted to do: Create a _simple_ text editor widget which supports VI(M) style keybindings but...
31
by: John Salerno | last post by:
Ok, I know it's been asked a million times, but I have a more specific question so hopefully this won't be just the same old post. I've tried a few different editors, and I really like UltraEdit,...
2
by: rockstar_ | last post by:
Hello all- I'm developing a Content Management software for my own site, and possibly package and deploy to other sites (for friends, family, etc.) The content management software is combined...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.