0

I wanted to add the resize event to an element (I know you can't add resize to a specific element, but it would be fine if the JS-function would be triggered on a resize of any kind - not the specific element).

I was thinking about this:

<div onresize="wrapperResize();"></div>

This somehow doesn't work (Safari user here). This however works:

<div onclick="wrapperResize();"></div>

Currently wrapperResize() only holds a simple console.log(). What could I do about this?

PS: This works great (traditional checked), what do I even do different?

EXTRA: The div has a fixed height and 33% of the body element wide. Even though the event should fire, when the window is resized I thought this may be the cause.

5
  • there is no native "resize" event because elements don't resize natively. if your stuff is resizable you must be using a js plugin, in which case you should consult the docs for said plugin. Commented Mar 4, 2016 at 20:57
  • What is this then? Commented Mar 4, 2016 at 20:58
  • Supported HTML tags: <body>. Did you try to add it to body instead of your div? Commented Mar 4, 2016 at 21:00
  • oh cool, didn't know about that new feature. according to your w3schools page it fires when the page is resized, not the element itself, so it doesn't really make sense to put the attribute on some arbitrary elemnt, do it with js like in the answer or put it on the body tag. Commented Mar 4, 2016 at 21:01
  • @SerhiyChupryk ... I'm stupid. Thank you really much. This works, it would be good to have it on the div though. Are there good alternatives? Commented Mar 4, 2016 at 21:01

2 Answers 2

2

I think you should set onresize handler on window and do it in javascript, not inline html.. Like so

window.onresize = yourFunction
Sign up to request clarification or add additional context in comments.

2 Comments

I'll try, wait a second.
Sure, I already wanted to, but had to wait for a few minutes.
2

You cannot attach a onresize event on a <div> container. It is only available for window for most of the browsers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.