How can I detect text selected in a div?

Victor Grazi

I have lines of text generated by ng-repeat, displayed within a div. I would like the user to be able to select from those lines and press a button, and have the application know which lines the user selected

Is there any way to do that in AngularJS

fracz

In order to capture selected text in a browser, try the Rangy library. I have created a small example of how to use it. I'm sure you can expand it to match your needs.

If you need to take action immediately after user select the text (without button), you should listen for mouseup event. The following directive should help:

angular.module('myModule').directive('watchSelection', function() {
    return {
        link: function(scope, element) {
            element.on('mouseup', function(event) {
                var selection = rangy.getSelection();
                // do something with selected text
            });
        }
    };
});

You may also find this answer interesting.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I detect text selected in a div?

From Dev

How can I detect "stylized" text?

From Dev

How can I detect which annotation was selected in MapView

From Dev

How to detect if selected text is wrapped in span tags

From Dev

How can I detect when the contents of a div are unloaded?

From Dev

How can I detect the inner html change in a div with angular 2?

From Dev

How can I detect where the text baseline is positioned

From Dev

how can i show selected image by ImgAreaSelect in a new div

From Dev

`ScrollToCaret` scrolls to the end of the selected text, how can I scroll to the begining of it?

From Dev

How can I get selected text in Ace editor?

From Dev

JavaScript - How can i set markers for selected text?

From Dev

How can I see if text is selected in the browser and then retrieve it?

From Dev

How can I pass the selected Kendo Menu Text to Controller

From Dev

How can I edit the selected text in Openlayers3?

From Dev

How can I log selected text with Firefox Addon Builder?

From Dev

JavaScript - How can i set markers for selected text?

From Dev

How can I check the word count of selected text in Notepad++?

From Dev

How can i get GWT HTML selected text?

From Dev

How I can determine which text is selected in EditText?

From Dev

How can I alert a text when an option is selected in jquery?

From Dev

How can I edit the selected text in Openlayers3?

From Dev

Detect hover on selected text

From Dev

How To Detect Clicked div text with same ids

From Dev

How can I make the active div move once another div is selected?

From Dev

How can I change the selected text background color in Rich text box wpf c#

From Dev

How can I display option text on the dropdown menu that is different than the selected text?

From Dev

How to detect text selected by double clicking using Firefox SDK (for addons)?

From Dev

How can I use CSS to center text in DIV

From Dev

How can I fade in and then fade out text inside a <div>

Related Related

  1. 1

    How can I detect text selected in a div?

  2. 2

    How can I detect "stylized" text?

  3. 3

    How can I detect which annotation was selected in MapView

  4. 4

    How to detect if selected text is wrapped in span tags

  5. 5

    How can I detect when the contents of a div are unloaded?

  6. 6

    How can I detect the inner html change in a div with angular 2?

  7. 7

    How can I detect where the text baseline is positioned

  8. 8

    how can i show selected image by ImgAreaSelect in a new div

  9. 9

    `ScrollToCaret` scrolls to the end of the selected text, how can I scroll to the begining of it?

  10. 10

    How can I get selected text in Ace editor?

  11. 11

    JavaScript - How can i set markers for selected text?

  12. 12

    How can I see if text is selected in the browser and then retrieve it?

  13. 13

    How can I pass the selected Kendo Menu Text to Controller

  14. 14

    How can I edit the selected text in Openlayers3?

  15. 15

    How can I log selected text with Firefox Addon Builder?

  16. 16

    JavaScript - How can i set markers for selected text?

  17. 17

    How can I check the word count of selected text in Notepad++?

  18. 18

    How can i get GWT HTML selected text?

  19. 19

    How I can determine which text is selected in EditText?

  20. 20

    How can I alert a text when an option is selected in jquery?

  21. 21

    How can I edit the selected text in Openlayers3?

  22. 22

    Detect hover on selected text

  23. 23

    How To Detect Clicked div text with same ids

  24. 24

    How can I make the active div move once another div is selected?

  25. 25

    How can I change the selected text background color in Rich text box wpf c#

  26. 26

    How can I display option text on the dropdown menu that is different than the selected text?

  27. 27

    How to detect text selected by double clicking using Firefox SDK (for addons)?

  28. 28

    How can I use CSS to center text in DIV

  29. 29

    How can I fade in and then fade out text inside a <div>

HotTag

Archive