HTML - attributes - onselect

revision:


Content

"onselect" attribute: when some text is selected syntax some examples


"onselect" attribute: when some text is selected

top

The onselect event occurs after some text has been selected in an element.

The onselect event is mostly used on <input type="text"> or <textarea> elements.


syntax

top

<element onselect="script"></element >

script: the script to be run on onselect.


some examples

top

example

Select some of the text:

codes:

                    <p class="spec">Select some of the text: <input type="text" 
                    value="Hello world!"
                    onselect="selectFunction()"></p>
                    <script>
                        function selectFunction() {
                        alert("You selected some text!");
                        }
                    </script>
                

example

Select some text:

codes:

                    <p class="spec">Select some text: <input type="text" value="Hello world!" onselect="selectText()"></p>
                    <p class="spec" id="demo-bb"></p>
                    <script>
                        function selectText() {
                        document.getElementById("demo-bb").innerHTML = "You selected 
                        some text!";
                        }
                    </script>