Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9150319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:35:47+00:00 2026-06-17T11:35:47+00:00

Which is best practice for displaying an HTML element that is initially to be

  • 0

Which is best practice for displaying an HTML element that is initially to be hidden?

  • Create the element in the HTML and hide it with CSS. When it is time to use it, show it with JavaScript.
  • When the element is needed, create and show it with JavaScript.

The downside to the former is that a potentially unnecessary element is in the HTML and must be initially hidden with CSS. The downside to the latter is that HTML is in the JavaScript file.

EDIT: Adding Examples

One example would be adding a loading indicator or displaying a modal window.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:35:47+00:00Added an answer on June 17, 2026 at 11:35 am

    There are a lot more factors that go in to this. If you are inserting a small element like a link or select list options, then dynamically generating them in javascript is a non-issue. If you are generating a repeating series of complex HTML, it might be a good idea to create a template of the html in the markup (so that the web designers can maintain it) and then make the template hidden in CSS. Then use javascript (e.g. jQuery) to clone the template and insert it in to the DOM. This gives you the benefit of using more native implementations to extend the DOM tree without all the nasty javascript-that-parses HTML mess.

    But ultimately the practicality comes down to this: Who is going to maintain the code? Will the more elegant solution be something that the maintainer will understand? Or will putting everything in javascript (despite its inelegance) be something that a junior coder would be able to expand or update as the need arises in the future?

    The vast majority of web browsers run on hardware that is ridiculously over-powered for what the user actually “needs”, at least in terms of web browsing. Because of this, inefficient solutions in Javascript are rarely ever an immediate issue. If you are targeting mobile browsers though, efficiency == battery life. So if you are doing heavy dom-manipulation then consider the suggestion above and see if it works for your case.

    Best of luck!
    -Brendan

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I dont know which is the best practice when we want to create a
Possible Duplicate: Why use partial classes? Which way is best practice and the best
From a speed and efficiency standpoint: which is considered best-practice, create a temporary object
What's best practice for structuring an activity, which should begin by displaying an animated
Which is best practice, which results in better performance? UPDATE: jsperf.com reports that (a)
Which is the best practice in this situation? I would like an un-initialized array
Which one is more acceptable (best-practice)?: namespace NP public static class IO public static
Hi I was wondering what is the best practice for tables in which you
XML Schema specifies occurrence indicators (maxOccurrence, minOccurrence). Is there a best practice in which
I need to create a special makefile rule, which is best explained by an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.