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

  • Home
  • SEARCH
  • 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 9209973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:58:13+00:00 2026-06-18T00:58:13+00:00

I have the following HTML generated by Drupal <fieldset id=webform-component-lunchset class=webform-component-fieldset form-wrapper style=> <div

  • 0

I have the following HTML generated by Drupal

<fieldset id="webform-component-lunchset" class="webform-component-fieldset form-wrapper" style="">
    <div id="webform-component-lunchset--lunch" class="form-item webform-component webform-component-radios webform-container-inline" style="">
        ...Radio Button div tags here
    </div>
</fieldset>
<fieldset id="webform-component-dinnerset" class="webform-component-fieldset form-wrapper" style="display: none;">
    <div id="webform-component-dinnerset--dinner" class="form-item webform-component webform-component-radios webform-container-inline" style="display: none;">
        ...Radio Button div tags here
    </div>
</fieldset>

My intent is to allow the user to choose a meal time based on the hour of the day when he initiates a booking. To do this I noticed that I have to change style=”display: none;” for the field set I want to hide and style=”” for the one I want displayed. I have the following Javascript statements to change the style attribute of the DIV tags but it doesn’t seem to work. Any help would be appreciated.

window.onload = (function() { 
    var today = new Date();
    var day = today.getDay();
    var hour = today.getHours();
    var lunchtime1 = document.getElementById('webform-component-lunchset');
    var lunchtime2 = document.getElementById('webform-component-lunchset--lunch');
    var dinnertime1 = document.getElementById('webform-component-dinnerset');
    var dinnertime2 = document.getElementById('webform-component-dinnerset--dinner');
    if (hour >= 15 && hour < 22) {
        lunchtime1.style="display: none;";
        lunchtime2.style="display: none;";
        dinnertime1.style=" ";
        dinnertime2.style=" ";
        sundaytime1.style="display: none;";
    }
});

Not sure why it isn’t working, would appreciate any help. Thank you in advance

  • 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-18T00:58:14+00:00Added an answer on June 18, 2026 at 12:58 am

    When you want to use the style property of a reference to a node, you’re using the DOM API. A DOMElement object has a property, called style, which has to be an object, too. So either write:

    lunchtime1.style.display = 'none';
    

    Or use the setAttribute method – so you can set the entire style attribute in one go:

    lunchtime1.setAttribute('style','display: block; background-color: #F00;');
    

    That should do the trick…

    note:
    As Tim Down pointed out, old IE’s don’t do setAttribute as well as decent browsers, so the first approach is the most reliable. I’m looking into the matter. IE doesn’t allow you to write someNode.setAttribute('onclick', 'clickHandler()'); for example.
    I’ve also encountered issues that seem to affect only certain elements (often form elements), but when it comes to setting the style attribute, I can’t be sure… Either you can’t set certain attributes, or you might not be able to set any attribute on some elements. Whatever… I’ll update this answer once I know more about this. (currently no windows boxes around, so no IE to test)

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

Sidebar

Related Questions

I have following HTML: <div class=olympics style=display: block; position: absolute; left: 250px; top: px;>
I have the following html form, which is generated dynamically: <ul class=precursorList> <li> Precursor
I have the following dynamically generated HTML <div id=1> <form name = inpForm> <input
I have the following html : <div class=mainmenu> <ul class=blue> <li class=><a href=tst/ id=a1_up><span
I have the following HTML element: <a href='#' class='receipt' id='{some id. generated dynamically}'>Receipt</a> I
I have the following HTML (excerpt from larger code-base) <div class=diary-event ui-corner-all title=[title]> <span
I have the following html code: <div id=result1 class=result> ... some html ... ...
I have the following HTML dinamically generated: ... <tr> <td><input type=text class=q value=5 name=q[]
using the following HTML which is dynamically generated: <div class=widget widget_1> <div class=widget_header widget_header_1></div>
I have the following HTML generated by form_tag and select_tag in Rails: <form accept-charset=UTF-8

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.