Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder oldcrazylegs's Avatar
    Join Date
    Feb 2004
    Location
    East Moline Illinois USA
    Posts
    414
    Thanks
    4
    Thanked 5 Times in 4 Posts

    Highlight Text n CODE Tag

    On the following page are two source code display boxes. I used the CODE Tag instead of Textareas. In a Textarea it is simple to highlight text highlight the text using onclick="this.select()". How can you do that in a CODE Tag?

    http://dwight.byethost31.com/best-ja...pdown-menu.htm

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    There's nothing special about a <code> tag. It acts the same, for these purposes, as a <div> or <p> or <span> tag. In no way does it resemble an <input> or <textarea> form field.

    If you wanted to use JS code to "hightlight" the text in any of those, you would have to put the desired text in, say, a <span> and apply a style to that <span>.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    i think your looking for DOM Ranges.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Well, sure, you can *FIND* a range when the user selects it.

    But I thought he was saying he wanted to be able to use JS to select a range. Is that possible, in any cross-browser way?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •