Note that there are some explanatory texts on larger screens.

plurals
  1. POchange value of attributes of a tag using javascript
    primarykey
    data
    text
    <p>I have the following HTML generated by Drupal</p> <pre><code>&lt;fieldset id="webform-component-lunchset" class="webform-component-fieldset form-wrapper" style=""&gt; &lt;div id="webform-component-lunchset--lunch" class="form-item webform-component webform-component-radios webform-container-inline" style=""&gt; ...Radio Button div tags here &lt;/div&gt; &lt;/fieldset&gt; &lt;fieldset id="webform-component-dinnerset" class="webform-component-fieldset form-wrapper" style="display: none;"&gt; &lt;div id="webform-component-dinnerset--dinner" class="form-item webform-component webform-component-radios webform-container-inline" style="display: none;"&gt; ...Radio Button div tags here &lt;/div&gt; &lt;/fieldset&gt; </code></pre> <p>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.</p> <pre><code>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 &gt;= 15 &amp;&amp; hour &lt; 22) { lunchtime1.style="display: none;"; lunchtime2.style="display: none;"; dinnertime1.style=" "; dinnertime2.style=" "; sundaytime1.style="display: none;"; } }); </code></pre> <p>Not sure why it isn't working, would appreciate any help. Thank you in advance</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload