Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Question about how to reference an Icon Button in a tile-list-item

ANSWERED

I want to create a tile-list similar to the Alarms application where each item in the list will contain text on the left side, and an image button on the right side. ( like selecting days of the week) The tile-list-item is defined in a Symbol. How can I reference each Icon button in the list?

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

 

 

function processList() {
  for (let i = 0; i < 5; i++) {

    var tile = document.getElementById('tile-'+i);
    let x = "foo";
    let y = "bar";

    tile.getElementById("mybutton").onclick = function(x,y) {    
      return function(){
        console.log("button clicked "+x+"-"+y);
      };
    }(x,y);
  }
}

 

You can also do the loop with classes

 

const  listItems = document.getElementsByClassName("listItem");
  for (var i = 0; i < listItems.length; i++) {
    //add magic here
  }

 

 

View best answer in original post

Best Answer
1 REPLY 1

 

 

function processList() {
  for (let i = 0; i < 5; i++) {

    var tile = document.getElementById('tile-'+i);
    let x = "foo";
    let y = "bar";

    tile.getElementById("mybutton").onclick = function(x,y) {    
      return function(){
        console.log("button clicked "+x+"-"+y);
      };
    }(x,y);
  }
}

 

You can also do the loop with classes

 

const  listItems = document.getElementsByClassName("listItem");
  for (var i = 0; i < listItems.length; i++) {
    //add magic here
  }

 

 

Best Answer