How to dynamically add or remove chips ?

web
mobile

Topic: How to dynamically add or remove chips ?

Accident.com pro asked 2 years ago

I want to modify chips in an input using javascript. Can anyone help me with this requirement ?

Here I am going to explain how to add chips dynamically.

Add the below line in your html.

 <div class="chips chips-initial"></div>

Add below code into JS function.

var s = "your_input";
var e = jQuery.Event("keydown");
e.which = 13; // # Some key code value
$(".chips-initial input").val(s);
$(".chips-initial input").trigger(e);
$('.chips').material_chip();

Note:Pass Your input into variable s;


terbach pro premium answered 8 months ago

That's working. But how to prevent XSS as tag input e.g.: alert('Hi');


TomekMakowski staff answered 8 months ago

You don't have to be worried about XSS becouse val() doesn't couse XSS

Best


Please insert min. 20 characters.
Status

Answered

Specification of the issue
  • User: Pro
  • Premium support: No
  • Technology: jQuery
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No