css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div id="demo">
  <label><input type="radio" name="example1" value="yes"><span></span> Yes</label>
  <label><input type="radio" name="example1" value="no"><span></span> No</label>

  <div class="conditional" data-cond-option="example1" data-cond-value="yes">
    <label><input type="checkbox" name="example2"><span></span> Are you sure?</label>
    <label><input type="checkbox" name="example3"><span></span> Really super sure?</label>
    
    <div class="conditional" data-cond-option="example2" data-cond-value="on">
      Hooray!
    </div>
    <div class="conditional" data-cond-option="example3" data-cond-value="on">
      Don't get cocky!
    </div>
  </div>
  
  <div class="conditional" data-cond-option="example1" data-cond-value="no">
    <p>That's a shame. Will you change your mind?</p>
    
    <label><input type="radio" name="example4" value="yes"><span></span> Yes</label>
    <label><input type="radio" name="example4" value="no"><span></span> No</label>
    
    <div class="conditional" data-cond-option="example4" data-cond-value="yes">
      Great!
    </div>
  </div>
  
  <p>
    <label>or choose:</label>
    <select class="select" name="example5">
      <option>Pick one!</option>
      <option value="yes">Yes!</option>
      <option value="no">No!</option>
    </select>
  </p>
  <div class="conditional" data-cond-option="example5" data-cond-value="yes">
    Works with selects!
  </div>
   <p>
    <label>or type:</label>
    <input type="text" name="example6" placeholder="yay">
  </p>
  <div class="conditional" data-cond-option="example6" data-cond-value="yay">
    Works with text input
  </div>
</div>
            
          
!
            
              /* Just makin' it look nice. */
body {
  background: #9fc7c0;
}
.conditional {
  margin: 1em 0 0.5em;
  border-top: 2px dotted #eee;
  padding-top: 1em;
  color: rgba(0,0,0,.7);
  font-size: .9em;
}
.conditional > .conditional {
  color: rgba(0,0,0,.5);
}

#demo {
  text-align: center;
  padding: 1.5em 3em;
  background: #fff;
  width: 60vw;
  margin: 2em auto;
  border-radius: .5em;
  font: 24px/30px 'Open Sans', Arial, Verdana, serif;
}

label {
  vertical-align: middle;
  position: relative;
}

label + label {
  margin-left: 1em;
}

input + span{
	position: absolute;
	left: 0;
  top: 4px;
	width: 15px;
	height: 15px;
  border: 2px solid #6ab5a8;
}

input[type=radio] + span {
  border-radius: 50%;
}

input[type=radio]:checked + span {
  background: rgba(106,181,169,1);
  background: -moz-radial-gradient(center, ellipse cover, rgba(106,181,169,1) 44%, rgba(255,255,255,1) 45%, rgba(255,255,255,1) 46%, rgba(255,255,255,1) 55%);
  background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(44%, rgba(106,181,169,1)), color-stop(45%, rgba(255,255,255,1)), color-stop(46%, rgba(255,255,255,1)), color-stop(55%, rgba(255,255,255,1)));
  background: -webkit-radial-gradient(center, ellipse cover, rgba(106,181,169,1) 44%, rgba(255,255,255,1) 45%, rgba(255,255,255,1) 46%, rgba(255,255,255,1) 55%);
  background: -o-radial-gradient(center, ellipse cover, rgba(106,181,169,1) 44%, rgba(255,255,255,1) 45%, rgba(255,255,255,1) 46%, rgba(255,255,255,1) 55%);
  background: -ms-radial-gradient(center, ellipse cover, rgba(106,181,169,1) 44%, rgba(255,255,255,1) 45%, rgba(255,255,255,1) 46%, rgba(255,255,255,1) 55%);
  background: radial-gradient(ellipse at center, rgba(106,181,169,1) 44%, rgba(255,255,255,1) 45%, rgba(255,255,255,1) 46%, rgba(255,255,255,1) 55%);
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6ab5a9', endColorstr='#ffffff', GradientType=1 );
}

input[type=checkbox]:checked + span:after {
  content: "\00d7";
  font-weight: bold;
  position: absolute;
  top: -7px;
  left: 1px;
  font-size: 20px;
  color: #6ab5a8;
}
 
input[type=radio],
input[type=checkbox] {
	/*hide the radio button*/
	filter:alpha(opacity=0);
	-moz-opacity:0;
	-khtml-opacity: 0;
	opacity: 0;
}

select,
input[type=text] {
  border-radius: 5px;
  padding: 6px 10px;
  border: 2px solid #9fc7c0;
  font-color: #666;
  font-size: 15px;
}
            
          
!
            
              /* * * * * * * * * * * * * * * * * *
* Show/hide fields conditionally
* * * * * * * * * * * * * * * * * */
(function($) {
  $.fn.conditionize = function(options){ 
    
     var settings = $.extend({
        hideJS: true
    }, options );
    
    $.fn.showOrHide = function(listenTo, listenFor, $section) {
      if ($(listenTo).is('select, input[type=text]') && $(listenTo).val() == listenFor ) {
        $section.slideDown();
      }
      else if ($(listenTo + ":checked").val() == listenFor) {
        $section.slideDown();
      }
      else {
        $section.slideUp();
      }
    } 

    return this.each( function() {
      var listenTo = "[name=" + $(this).data('cond-option') + "]";
      var listenFor = $(this).data('cond-value');
      var $section = $(this);
  
      //Set up event listener
      $(listenTo).on('change', function() {
        $.fn.showOrHide(listenTo, listenFor, $section);
      });
      //If setting was chosen, hide everything first...
      if (settings.hideJS) {
        $(this).hide();
      }
      //Show based on current value on page load
      $.fn.showOrHide(listenTo, listenFor, $section);
    });
  }
}(jQuery));
  
 $('.conditional').conditionize();
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console