Static text highlighting -- can it be done?

Discussion in 'Javascript' started by bryan, Jan 6, 2007.

  1. bryan

    bryan Guest

    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.
     
    bryan, Jan 6, 2007
    #1
    1. Advertising

  2. bryan

    pcx99 Guest

    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
     
    pcx99, Jan 6, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alan Cantor

    Code Text Highlighting Question

    Alan Cantor, Oct 7, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    478
    Alan Cantor
    Oct 7, 2003
  2. JemPower

    Highlighting text

    JemPower, Oct 31, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    335
    Natty Gur
    Nov 2, 2003
  3. Xavier Bourguignon

    input text highlighting problem

    Xavier Bourguignon, Oct 29, 2003, in forum: HTML
    Replies:
    7
    Views:
    983
  4. Zhidian Du
    Replies:
    0
    Views:
    178
    Zhidian Du
    Feb 21, 2004
  5. Aria
    Replies:
    3
    Views:
    107
    Janwillem Borleffs
    Oct 13, 2005
Loading...

Share This Page