Function to insert a tab in a textarea by pressing TAB with jQuery

  Snippets   -   06/08/2015


This function allows you to insert tabs in a textarea when you press the TAB key on your keyboard.


Demonstration


Associated code

<textarea class="oft_tab_enable"></textarea>


How to use

To add tabs when you press the TAB key, just apply the class oft_tab_enable on the desired field. Since it is a class, it is possible to apply multiple fields on the same page.


Integrating the function to your site

The use of the library has been simplified to the maximum.


Solution 1: Quick and easy, simply add the link to our CDN

<script src="http://cdn.online-free-tools.com/js/oft_tab_enable.min.js"></script>


Solution 2: Download the library and call it on your site



If you choose this option, you simply add the line below and adapt the path to access the .js file. It is recommended to add this line after the other javascript files.


<script src="/js/oft_tab_enable.min.js"></script>


Change the type of tab

You can change the type of tab by adding the javascript line below before calling our library. By default, the tab is a \t.


// Default value
var oft_tab_type = "\t";

Example: 4 spaces per tab

var oft_tab_type = "    ";


Example: 2 HTML spaces per tab

var oft_tab_type = "&nbsp;&nbsp;";




Tags :  
jQuery
  
HTML
  


Autodidact passionate about the web, I'm always looking for new challenges.
Founder of Online-Free-Tools.com.



  Comments


No comment

Add a comment




 FR     EN  

Copyright 2024 -   Contact us - 2024-12-03 18:54:03