Skip to content

Instantly share code, notes, and snippets.

@Farmatique
Created March 10, 2017 17:07
Show Gist options
  • Save Farmatique/2e88bd69ab6af0ea94e03ec353636cf1 to your computer and use it in GitHub Desktop.
Save Farmatique/2e88bd69ab6af0ea94e03ec353636cf1 to your computer and use it in GitHub Desktop.
2 colors inside input field text+asterisk
<form>
<div class="input-wrapper">
<input type="text" id="name" name="name" required="required" />
<label for="name">Name</label>
<br/>
</div>
<input type="submit" />
</form>
.input-wrapper {
width: 160px;
position: relative;
}
input[type=submit] {
width: auto;
}
input[required] + label {
color: #999;
font-family: Arial;
font-size: .8em;
position: absolute;
left: 5px;
top:2px;
}
input[required] + label:after {
content:'*';
color: red;
}
jQuery('form').find('input, textarea').focus(function(){
var self = jQuery(this);
if (self.val() != ""){
// console.log('full')
self.next().css('display', 'none')
} else {
// console.log('empty')
self.next().css('display', 'none')
}
});
jQuery('form').find('input, textarea').blur(function(){
var self = jQuery(this);
if (self.val() != ""){
self.next().css('display', 'none')
} else {
self.next().css('display', 'inline-block')
}
});
// Fiddle here http://jsfiddle.net/Farmatique/mzp7rm5t/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment