0

I have a dynamic data to display in front end.I have 'see more' and 'see less' option to each data.When Clicking the 'see more' option need to call some api. So I need to avoid 'see more' click. if i have five records and calling see more option using javascript element click() method in angular. this is not working for html collection.

setTimeout(() => {
  let getSeeMoreEle = document.getElementsByClassName('see-more');
  for (let index = 0; index < getSeeMoreEle.length; index++) {
     getSeeMoreEle[index].click();
  }
}, 500);
chana
  • 183
  • 2
  • 19
Manikandan
  • 51
  • 1
  • 11

2 Answers2

0
      let getSeeMoreLength = document.getElementsByClassName('see-more');

      for (let index = 0; index < getSeeMoreLength.length; index++) {
             let getSeeMoreEle:HTMLElement = document.getElementsByClassName('see-more')[index] as HTMLElement;
            getSeeMoreEle.click();
       }

this code worked.

Manikandan
  • 51
  • 1
  • 11
-3

You can use jQuery or simple JS methods to do that. In this question, you can use this method to do that out from browser console. But you can equally apply that from the code.

$('#button1').click();
document.getElementById('button1').click();
Evgenii Klepilin
  • 695
  • 1
  • 8
  • 21