jQuery Plugin To Select Single Word Within An Element - GetWordByEvent

jQuery Plugin To Select Single Word Within An Element - GetWordByEvent
File Size: 4.66 KB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

GetWordByEvent is a simple to use jQuery plugin which allows the user to pick up a single word within a specific element by custom events (click, hover or right-click).

How to use it:

1. Include jQuery library and the jQuery GetWordByEvent plugin on the html page.

<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="jquery.get-word-by-event.js"></script>

2. Create an empty element that will output the word you pick up.

<label id="click-label"></label>

3. Pick up a single word on click.

$('p').getWordByEvent('click', function(event, word) {
  $('#output').html('Clicked: <b>' + word + '</b>');
});

4. Pick up a single word on right click.

$('p').getWordByEvent('contextmenu', function(event, word) {
  event.preventDefault(); // Prevent popup menu
  $('#output'').html('Right clicked: <b>' + word + '</b>');
});

5. Pick up a single word on hover.

$('#move-text').getWordByEvent('mousemove', function(event, word) {
  $('#output').html('Word under cursor: <b>' + word + '</b>');
});

This awesome jQuery plugin is developed by megahertz. For more Advanced Usages, please check the demo page or visit the official website.