-1

Use tag to show/hide div when click when JavaScript is disabled. Tried adjusting following example Show hide divs on click in HTML and CSS without jQuery but that doesn't seem to work.

From this question How to detect if JavaScript is disabled? i assumed that there isn't a convenient way to check if JS is disabled like:

if(JS is disabled){
     // show <a> tag that words with jQuery to display div
} else {
    // show label to show/hide div onclick
}

Any ideas will be welcomed.

Question How to make "a" tag to show a mini login form stored in "div" when JavaScript is disabled. Because when it's enabled it ?

Below is coresponding code of tag "a" and "div".

<ul class="nav nav-bar pull-right" >
<li class="dropdown" id="menuLogin">

<a class="dropdown-toggle" href="#" for="_1" data-toggle="dropdown" id="navLogin">Login</a>
<div class="dropdown-menu" style="padding-left:17px; left:-70px; width:200px;">
    <?php 
        $form_sm = $this->form_sm;
        $form_sm->prepare();
        echo $this->form()->openTag($form_sm);
    ?>

    <dl class="form">
    <dd><?php
            echo $this->formElement($form_sm->get('email'));
            echo $this->formElementErrors($form_sm->get('email'));
        ?></dd>
    <dd><?php
            echo $this->formElement($form_sm->get('password'));
            echo $this->formElementErrors($form_sm->get('password'));
        ?></dd>
    <li class="divider" style="width:78%"></li>
    <dd><?php
            echo $this->formElement($form_sm->get('send'));
            echo $this->formElementErrors($form_sm->get('send'));
        ?></dd>
   <?php echo $this->form()->closeTag() ?>      
</div>

</li>
</ul>

It uses a Bootstrap3 and Zend Framework components and by clicking "a" tag following line

<li class="dropdown" id="menuLogin">

change to

<li class="dropdown open" id="menuLogin">
Community
  • 1
  • 1
I M
  • 61
  • 1
  • 9

1 Answers1

0

You can use checkbox hack to do it. Since it is pure CSS there are some limitations. The elements you want to hide have to be siblings or children of the label you will use so you can select them when you get the :checked status. You can't go up to a element's parent in CSS.

Here is an example: http://jsfiddle.net/carloscalla/msaccf9w/

HTML:

<label class="hide_action" for="chk1">Action toggle</label>
<input id="chk1" type="checkbox" />
<div>Sibling div</div>

CSS:

.hide_action{
  display:block;
  background-color: yellow;
}
.hide_action + input{ /* or #chk1 */
  display:none;
}
.hide_action + input + *{ /* or #chk1 (selector for what you want to hide) */
  display:none;
}
.hide_action + input:checked + *{ /* or #chk1:checked (selector for what you want to hide) */
  display:block;
}

You can not go up a parent and hide other element since you won't be able to get a selector for it. You can go down in children or siblings.

In this example I use + input to select the adyacent input to the label if you don't want them to be together you can identify it by an id as in the CSS comments.

Carlos Calla
  • 6,556
  • 2
  • 16
  • 23