I am trying to randomize the display of divs in Polymer, but am having trouble translating this post into the framework.
ready() {
super.ready();
let cards = this.shadowRoot.querySelectorAll('.className');
for(var i = 0; i < cards.length; i++){
let target = Math.floor(Math.random() * cards.length -1) + 1;
let target2 = Math.floor(Math.random() * cards.length -1) +1;
cards.eq(target).before(cards.eq(target2));
}
This fails when cards.eq is called...
Could this be solved with a dom-repeat?
The solution you linked uses jQuery to select the
divs whereas in your casecards, being the result of a nativequerySelectorcall, doesn't have theeqandbeforemethods.Yes: you could store the data model behind the divs in a property and shuffle it before rendering the divs: