0

I am using backbone. I need to obtain an element's width inside the backbone render function. But unfortunately, that is not possible, because the element has not yet been added to the dom. Is there a way to obtain an element's width inide the backbone render function?

J K
  • 4,883
  • 6
  • 15
  • 24

1 Answers1

0

You can't get the width without actually inserting the view to DOM, however, you can get the value by inserting it without the user seeing it by giving it negative z-index, opacity:0 etc, something along this answer.

If you really really don't want to insert it in DOM for some reason, then you can make a hidden clone of it and insert that instead to find the dimensions.

Community
  • 1
  • 1
T J
  • 42,762
  • 13
  • 83
  • 138