Bogdan
Bogdan

Reputation: 483

bootstrap-tags-input adding a class to the generated input

I would like to add a class or other attributes to the input generated by bootstrap

<input type="text" value="">
$('input').tags-input();

generates:

<div class="bootstrap-tagsinput">
  <input type="text" placeholder="add tags" style="width: 8em !important;">
</div>

I would like to add a class with: https://bootstrap-tagsinput.github.io/bootstrap-tagsinput/examples/

input

Returns the tagsinput's internal , which is used for adding tags. You could use this to add your own typeahead behaviour for example.

var $elt = $('input').tagsinput('input');

I don't seem to understand how would a class be added

Thank you

Upvotes: 5

Views: 7059

Answers (1)

Dhiraj
Dhiraj

Reputation: 33618

Firstly, tagsinput is initialized like this

$("input").tagsinput();

The method tagsinput('input') returns the input element to which other jQuery methods can be used like this

var $input = $("input").tagsinput('input');
$input.addClass('custom-class');

Upvotes: 9

Related Questions