I've got the following script that works fine as is:
eventslist.bundle.js
// import {
// equalheight,
// } from './functions';
window.addEventListener('DOMContentLoaded', (event) => {
/**
* Will ensure that all elements are of equal height
* @param {DOMElem} selector
*/
const equalheight = (selector) => {
var currentTallest = 0,
currentRowStart = 0,
rowDivs = new Array(),
$el,
topPosition = 0;
$(selector).each(function () {
...
However, when I move this function into the functions.js file, and uncomment the import statement:
functions.js
import {$} from 'jquery';
/**
* Will ensure that all elements are of equal height
* @param {DOMElem} selector
*/
export const equalheight = (selector) => {
var currentTallest = 0,
currentRowStart = 0,
rowDivs = new Array(),
$el,
topPosition = 0;
$(selector).each(function () {
And then update my bundle script:
eventslist.bundle.js
import {
equalheight,
} from './functions';
window.addEventListener('DOMContentLoaded', (event) => {
// /**
// * Will ensure that all elements are of equal height
// * @param {DOMElem} selector
// */
// const equalheight = (selector) => {
// var currentTallest = 0,
// currentRowStart = 0,
// rowDivs = new Array(),
// $el,
// topPosition = 0;
// $(selector).each(function () {
I get an error on the $(selector).each(function () { line telling me that
Uncaught TypeError: Object(...) is not a function
I'd like to remove this function from the script so it's re-usable. But what am I doing wrong? jQuery is a NPM dependency and from what I've read, this is how to import it.
Will ensure that all elements are of equal heightyou don't need JS for that. CSS Flexbox does it out of the box.display:flex; align-items:stretch;job done<script src=".../jquery.js">