Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
  <head>
    <title>HTML5 Manejo del Atributo 'required' usando JQuery</title>
  </head>  
  <body>
    <div class="cform">
      <form actio="#">
   <input type="text" name="field1" placeholder="Nombre (*)" required/> 
   <input type="email" name="field2" placeholder="Email (*)" required/>
   <input type="tel" name="field2" placeholder="Telefono" />
   <input type="submit" value="Enviar" />
      </form>  
      <span class="requeridof">(*) Campo requerido</span>
    </div> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  </body>    
 </html>  
              
            
!

CSS

              
                .cform{
    font: 95% Arial, Helvetica, sans-serif;
    max-width: 400px;
    margin: 10px auto;
    padding:30px  16px;
    background: #a3ccff;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    border: 5px solid #0056c1;
    
}

.form-error {
	display:none;
	position:absolute;
	top:0;
	right:0;
	font-size:11px;
	line-height:20px;
	font-style:italic;
	background:#9A2C2C;
	color:#FFF;
	padding:5px 10px;
	box-shadow:inset 0 -1px 3px rgba(0,0,0,0.3),inset 0 1px 3px rgba(0,0,0,0.3);
	-webkit-box-shadow:inset 0 -1px 3px rgba(0,0,0,0.3),inset 0 1px 3px rgba(0,0,0,0.3);
	-moz-box-shadow:inset 0 -1px 3px rgba(0,0,0,0.3),inset 0 1px 3px rgba(0,0,0,0.3);
}


.cform input[type="tel"],
.cform input[type="text"],
.cform input[type="date"],
.cform input[type="datetime"],
.cform input[type="email"],
.cform input[type="number"],
.cform input[type="search"],
.cform input[type="time"],
.cform input[type="url"],
.cform textarea,
.cform select 
{
    -webkit-transition: all 0.30s ease-in-out;
    -moz-transition: all 0.30s ease-in-out;
    -ms-transition: all 0.30s ease-in-out;
    -o-transition: all 0.30s ease-in-out;
    outline: none;
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    width: 100%;
    background: #fff;
    margin-bottom: 4%;
    border: 1px solid #ccc;
    padding: 3%;
    color: #555;
    font: 95% Arial, Helvetica, sans-serif;
}
.cform input[type="tel"]:focus,
.cform input[type="text"]:focus,
.cform input[type="date"]:focus,
.cform input[type="datetime"]:focus,
.cform input[type="email"]:focus,
.cform input[type="number"]:focus,
.cform input[type="search"]:focus,
.cform input[type="time"]:focus,
.cform input[type="url"]:focus,
.cform textarea:focus,
.cform select:focus
{
    box-shadow: 0 0 5px #43D1AF;
    padding: 3%;
    border: 1px solid #43D1AF;
}

.requeridof {
  margin-top:10px;
  text-align:center;
  display:block;
  font: italic bold 12px/30px Georgia, serif;
  color:red;
}

.cform input[type="submit"], 
.cform input[type="button"]{
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    width: 100%;
    padding: 3%;
    background: #0049a4;
    border-bottom: 2px solid #30C29E;
    border-top-style: none;
    border-right-style: none;
    border-left-style: none;    
    color: #fff;
}
.cform input[type="submit"]:hover,
.cform input[type="button"]:hover{
    background: #025dcd;
}

              
            
!

JS

              
                // Demo script, feature detect inverted
$(function () {
			
			// feature detect
			var supportsRequired = 'required' in document.createElement('input');
			
			// loop through required attributes
			$('[required]').each(function () {
			
				// if 'required' isn't supported
				if (!supportsRequired) {
				
					// this
					var self = $(this);
				
					// swap attribute for class
					self.removeAttr('required').addClass('required');
					
					// append an error message
					self.parent().append('<span class="form-error">Requerido</span>');
					
				}
				
			});
			
			// submit the form
			$('.form').on('submit', function (e) {
			
				// loop through class name required
				$('.required').each(function () {
				
					// this
					var self = $(this);
					
					// check shorthand if statement for input[type] detection
					var checked = (self.is(':checkbox') || self.is(':radio')) 
					? self.is(':not(:checked)') && $('input[name=' + self.attr('name') + ']:checked').length === 0 
					: false;
					
					// run the empty/not:checked test
					if (self.val() === '' || checked) {
							
						// show error if the values are empty still (or re-emptied)
						// this will fire after it's already been checked once
						self.siblings('.form-error').show();
						
						// stop form submitting
						e.preventDefault();
					
					// if it's passed the check
					} else {
					
						// hide the error
						self.siblings('.form-error').hide();
						
					}
					
				});
				
				// all other form submit handlers here
			
			});
			
			// key change on all form inputs
			$('input, textarea', '.form').on('blur change', function () {
			
				// this
				var self = $(this);
					
				// check shorthand if statement for input[type] detection
				var checked = (self.is(':checkbox') || self.is(':radio')) 
				? self.is(':not(:checked)') && $('input[name=' + self.attr('name') + ']:checked').length === 0 
				: false;
				
				// if empty on change, i.e. if data is removed
				if (self.val() === '' || checked) {
				
					// show/keep the error in view
					self.siblings('.form-error').show();
				
				// if there's a value or checked
				} else {
				
					// hide the error
					self.siblings('.form-error').hide();
					
				}
				
			});
		
		});

              
            
!
999px

Console