Javascript in Gatsbyjs website

Javascript in Gatsbyjs website
0

How to call JavaScript in a Gatsbyjs website. I am using below code but don’t understand where to add the JS code. I am using this source https://codepen.io/jackocnr/pen/EyPXed

Please advise.

HTML file

<h1>International Telephone Input - BOOTSTRAP INPUT GROUP</h1>
<form>
  <div class="input-group">
    <input type="tel" class="form-control">
    <span class="input-group-addon">Tel</span>
  </div>
  <br>
  <div class="input-group">
    <input type="tel" class="form-control">
    <span class="input-group-addon">Tel</span>
  </div>
</form>

CSS File

body {
  margin: 20px;
}
form {
  width: 300px;
}

// workaround
.intl-tel-input {
  display: table-cell;
}
.intl-tel-input .selected-flag {
  z-index: 4;
}
.intl-tel-input .country-list {
  z-index: 5;
}
.input-group .intl-tel-input .form-control {
  border-top-left-radius: 4px;
  border-top-right-radius: 0;
  border-bottom-left-radius: 4px;
  border-bottom-right-radius: 0;
}

JS file

$("input").intlTelInput({
  utilsScript:
    "https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/8.4.6/js/utils.js"
});

Did you look at the docs? I think the fact the lib is added to the window object is an issue with gatsby.

It would probably be better to look for a custom component instead, e.g. here is a react component and here are the gatsby docs on adding react components.