0

I have a hidden form element, and it has an input tag with an attribute of 'value'.

Will reading the value of 'value' (using getElementById) cause a reflow? Will changing the value of 'value' (using getElementById & setAttribute) while the element is hidden cause a reflow?

I know different browsers behave differently but was just looking for some input on this subject. I have also set 'display' to 'none' - will this effect the behaviour of the questions above?

Thanks in advance for any help!

user1360809
  • 725
  • 2
  • 13
  • 24
  • See my answer below. You can accept this answer for the link that I have provided. However, I am suspecting that you are onto something else which has raised this question in your mind. Is it? – Chandranshu Nov 19 '13 at 10:10
  • Thanks, I found that page - specifically in this case does it not relfow (or repaint) as I am only changing an attribute that is not to do with style? That doesn't make sense, what if value was for a textArea...? – user1360809 Nov 19 '13 at 10:17
  • 1
    TextArea doesn't have a value attribute. Whatever you write between the opening and closing tags is what gets rendered. In any case, your question deals with a hidden element. So, still no reflow. – Chandranshu Nov 19 '13 at 10:19
  • Awesome, thanks, coderjoe in the link summarises the issues well...would you say making changes to a hidden element in the DOM then when done set it to display would be a good technique to avoid reflows? – user1360809 Nov 19 '13 at 10:21
  • Yes, it is the recommended way. – Chandranshu Nov 19 '13 at 10:35
  • On second thoughts, if you have your text ready and you set it as the value of the input, it'll result in a single reflow which is independent of whether the element is hidden or not. It'll only matter if you are building your input step by step. – Chandranshu Nov 19 '13 at 10:44
  • ah...so making changes (not reading) to a hidden element WILL cause a reflow...!!!? – user1360809 Nov 19 '13 at 10:58
  • 1
    **NO!** This was to continue your discussion about _showing_ the hidden element after updating the value. – Chandranshu Nov 19 '13 at 11:00
  • Sorry, that clears everything up! Makes sense, a good way to get everything ready then press the big red button for a single reflow... – user1360809 Nov 19 '13 at 11:02
  • Totally! Now where is my prize? :) – Chandranshu Nov 19 '13 at 11:03
  • Are you currently employed in this area? – user1360809 Nov 19 '13 at 11:07
  • haha - I was going to say your prize was being able to feed and clothe yourself! But an accept of the answer would be just as good - really?? ;) – user1360809 Nov 19 '13 at 11:40
  • I normally tend to answer questions which have some views but no answers. Answering some questions often need specialized knowledge and sometimes research as well. Sometimes it hurts (like today) to not get an accept even after a long conversation :) – Chandranshu Nov 19 '13 at 11:52

1 Answers1

1

No, reading or writing the value attribute will not cause reflow. See this question and its accepted answer: When does reflow happen in a DOM environment? for more details.

Community
  • 1
  • 1
Chandranshu
  • 3,669
  • 3
  • 20
  • 37