JQuery TextExt plugin: add a tag after pressing the space bar and click on any button

I have one input

<input type="text" style="width:200px" id="myInputTags" placeholder="add tag" /> <input type="button" id="btnId" /> 

in script

 jQuery("#myInputTags").textext({ plugins: 'tags' }); 

Now, when I press the enter button in this input, a tag is created, but I want to add these tags after clicking on my button and after pressing the space bar, some suggestion?

+5
source share
1 answer

Hey.

 jQuery("#myInputTags") .textext({ plugins: 'tags, prompt', prompt: 'add tag' }) .keypress(function(event){ //'Space' key is pressed in keyboard if(event.which==32){ addTag(); } }); jQuery("#btnId").click(function(){ addTag(); }) function addTag(){ //Take the value from text input var tag = $('#myInputTags').val(); //Clear the text input and add tag $('#myInputTags').val('').textext()[0] .tags().addTags([tag]); } 

See a demo of this

Docs: TexExt - Add Tags Directly

+5
source

Source: https://habr.com/ru/post/1203955/


All Articles