select html within a div

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pbeisel@gmail.com

    select html within a div


    i would like to select the HTML within a DIV when a user clicks in it.
    then the user can ctrl-c and get the HTML on the clipboard (much as if
    the user drag-selected and area of the page and then hit ctrl-c).

    the problem with the drag to select method is that its imprecise or
    hard for the user to control. if i could simply select the text for
    him, then all he needs to do i click and ctrl-c.

    for a standard textbox i simply have an onclick handler set to
    'this.select(); '. all the user has to do is click on the textbox
    (which is a non-editable, meaning read-only) and the text is selected
    and then hit ctrl-c and onto the clipboard it goes...

    of course, this doesn't work for the DIV.

    any ideas?

  • Bart Van der Donck

    #2
    Re: select html within a div

    pbeisel@gmail.c om wrote:
    i would like to select the HTML within a DIV when a user clicks in it.
    then the user can ctrl-c and get the HTML on the clipboard (much as if
    the user drag-selected and area of the page and then hit ctrl-c).
    >
    the problem with the drag to select method is that its imprecise or
    hard for the user to control. if i could simply select the text for
    him, then all he needs to do i click and ctrl-c.
    >
    for a standard textbox i simply have an onclick handler set to
    'this.select(); '. all the user has to do is click on the textbox
    (which is a non-editable, meaning read-only) and the text is selected
    and then hit ctrl-c and onto the clipboard it goes...
    >
    of course, this doesn't work for the DIV.
    >
    any ideas?
    One workaround:

    <form>
    <div id="D">a<hr>b<f ont color="red">c</font></div>
    <input type="button" value="Get HTML from div" onClick="doSele ct()">
    <br>
    <textarea name="E" cols="30" rows="10"></textarea>
    </form>
    <script type="text/javascript">
    function doSelect() {
    document.forms[0].E.value = document.getEle mentById('D').i nnerHTML
    document.forms[0].E.select()
    }
    </script>

    --
    Bart

    Comment

    • pbeisel@gmail.com

      #3
      Re: select html within a div


      i came across this:



      which solves the problem quite nicely.

      pbeisel@gmail.c om wrote:
      i would like to select the HTML within a DIV when a user clicks in it.
      then the user can ctrl-c and get the HTML on the clipboard (much as if
      the user drag-selected and area of the page and then hit ctrl-c).
      >
      the problem with the drag to select method is that its imprecise or
      hard for the user to control. if i could simply select the text for
      him, then all he needs to do i click and ctrl-c.
      >
      for a standard textbox i simply have an onclick handler set to
      'this.select(); '. all the user has to do is click on the textbox
      (which is a non-editable, meaning read-only) and the text is selected
      and then hit ctrl-c and onto the clipboard it goes...
      >
      of course, this doesn't work for the DIV.
      >
      any ideas?

      Comment

      Working...