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?
Asked
Active
Viewed 489 times
0
-
3Important question: what changes the height of your element? – Tomas M Aug 01 '15 at 17:35
-
2And add the relevant js code and html if applicable. – wOxxOm Aug 01 '15 at 17:39
-
1Is the element whose height is changing doing so due to some user activity or timer? I agree with @wOxxOm, we need to see the applicable code and html. – Tyree Jackson Aug 01 '15 at 17:43
-
I have JavaScript changing the height of the element. I do have a transition property on the element so it takes a second to update the height. – LeeTheCoder Aug 01 '15 at 20:13
-
And also, it's user interaction. – LeeTheCoder Aug 01 '15 at 20:15
-
I'll post the code on PasteBin: http://pastebin.com/tZrhAP1c – LeeTheCoder Aug 01 '15 at 20:25
3 Answers
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.
-
Okay, I'll try this out. Is there anyway to stop it from running after it's run "true" once? – LeeTheCoder Aug 01 '15 at 20:14
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
-
1We 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