Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Selection

Jetpack's selection API provides a method for detecting the selections made by the user. Features can get, set, and listen for selection events in HTML or plain text.

The namespace for this api is jetpack.selection. This API currently lives in the future and must be imported for use: jetpack.future.import("selection");

Getting and Setting the Selection

The current version of jetpack.selection includes these formats: .text and .html

Getting the selection

The following is an example of getting the selection from the user.

jetpack.import.future("selection");

var textOfSel = jetpack.selection.text;
var htmlOfSel = jetpack.selection.html;

Setting the selection

The following is an example of getting the selection from the user.

jetpack.import.future("selection");

jetpack.selection.text = 'Hello';
jetpack.selection.html = '<b>Hello</b>';

Methods

onSelection(func function)This method allows you to execute an event function when a selection is made.
funcA function to be called when the selection is made. This function receives no arguments. Use jetpack.selection.*. function

Adding a selection event

jetpack.selection.onSelection( fn );

Removal of a selection event

jetpack.selection.onSelection.unbind( fn );

Verbose Example

The following example will bold the html that you select.

jetpack.import.future("selection");
jetpack.selection.onSelection(function(){
    var html = jetpack.selection.html;
    jetpack.selection.html = "<b>" + html + "</b>";
});

Document Tags and Contributors

 Contributors to this page: Sheppy, JetpackBot, Aza
 Last updated by: Sheppy,