0

I'm trying to delete an html element using JavaScript when another html element reaches a certain height. But, it requires me to keep clicking the button that triggers the code to keep checking if the height of that element has changed. Is there anyway around this?

gariepy
  • 3,576
  • 6
  • 21
  • 34

3 Answers3

1

Set an event listener on the object that checks the height, when the object reaches the specified height then the statement will be true and begin to execute which would simply just remove the object. Post your code and I'll help you out.

Jordan Davis
  • 1,485
  • 7
  • 21
  • 40
1

try to check every interval of time.

function check() {
  // do the checking here
}

// check every 30 ms
setInterval(check, 30);

Note: Do not use while statements because it blocks the rendering of the page until it is executed.

0

Use setInterval() and put your code there with interval time

var myInterval = setInterval(function(){
    //your code or event trigger comes here
    //when done clearInterval(myInterval)
}, 500);//each 0.5 second

Let me know if you want to know more or I explain wrong

Hossein Shahsahebi
  • 6,348
  • 5
  • 24
  • 38
  • I won't down vote this because it could be a solution depending on what your trying to achieve but unless the height of the object is scaling by time this wouldn't be a good solution. – Jordan Davis Aug 01 '15 at 17:42
  • @JordanDavis at least thanks for not down voting. what about this solution? http://stackoverflow.com/questions/172821/detecting-when-a-divs-height-changes-using-jquery – Hossein Shahsahebi Aug 01 '15 at 17:47
  • 1
    We really just need to figure out how he is scaling the object via a timing mechanism or some user interaction... I'm just saying if he were to set a listener on the object height then it would be compatible with either timing or user-interaction. – Jordan Davis Aug 01 '15 at 17:55