Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
jquery-textrange
Advanced tools
Readme
This jQuery plugin is for easily finding the starting and ending positions of selected text in text fields and textareas. It can also be used to set the selection, and replace the selection with given text (or insert text wherever the cursor is in the text field or textarea).
Include the file directly using <script>
tags:
<script src="https://code.jquery.com/jquery-latest.min.js"></script>
<script src="jquery-plugins/jquery-textrange.js"></script>
:memo: note: jquery-textrange can be loaded through any UMD-compatible Javascript Module Loader.
You can use this method to get all the information on the selected text of an element or a specific bit of information.
$('input[name="example"]').textrange('get');
or for short:
$('input[name="example"]').textrange();
This will return a JSON object with the following information:
{
"position": // cursor location in the text field)
"start": //starting position of the selected text in the text field
"end": // ending position of the selected text in the text field
"length": // the length of the selected text in the text field
"text": // the text that is selected
}
This function can also be used to get a particular property of the object.
For example, this will obtain the starting location of the selected text:
var start = $('input[name="example"]').textrange('get', 'start');
You can use this method to set the starting and ending locations of the selected text in an element.
It works much like PHP's substr(), so if you're familiar with that, it should be a breeze! Here are some examples, anyway.
For the following examples, let's say input[name="example"]
contains the text
abcdef
.
$('input[name="example"]').textrange('set'); // selects "abcdef" (select all)
$('input[name="example"]').textrange('set', 2); // selects "cdef"
$('input[name="example"]').textrange('set', 2, 3); // selects "cde"
$('input[name="example"]').textrange('set', 2, -2); // selects "cd"
$('input[name="example"]').textrange('set', -3); // selects "def"
$('input[name="example"]').textrange('set', -2, 1); // selects "e"
$('input[name="example"]').textrange('set', -4, -1); // selects "cde"
If you're looking to set the cursor at one specific location, you can use 0
for length, or you can use $().textrange('setcursor')
(see below).
You can use this method to set the location of the cursor in your text field.
To set the cursor at the fifth character position:
$('input[name="example"]').textrange('setcursor', 5);
You can use this method to replace the selection with given text.
$('input[name="example"]').textrange('replace', 'some text');
There is also an insert
alias for replace
if you're using this method to
insert text at the cursor location. They work the same way.
FAQs
A jQuery plugin for getting, setting and replacing the selected text in input fields and textareas.
The npm package jquery-textrange receives a total of 661 weekly downloads. As such, jquery-textrange popularity was classified as not popular.
We found that jquery-textrange demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.