This question already has an answer here:
I cannot reach to add an image after an input element for form validation with JQuery. Doesn't work also if I add the class manually on the element...
HTML:
<script type="text/javascript">
$(document).ready(function(){
$('#last_name').addClass('cross');
});
</script>
<label for="last_name">*Last Name:</label>
<input type="text" id="last_name" value="<?=$last_name?>" />
CSS:
.cross:after {
content:url(/ico/cross.png);
/* Tried also with:
content:url('/ico/cross.png');
AND
content: '';
background:url(/ico/no_check.png); */
}
The
::after
pseudo-element places the 'element' within the element itself 'after' its contents (not after the element), aninput
is a void element that cannot contain any other HTML. This cannot work, unfortunately. See, for example: "CSS :after pseudo element on INPUT field."With jQuery, however, you could add a new image (not a background-image, or pseudo-element) using the following (though untested):
Simple demo.
References:
after()
.I think you would do better using this route:
Live Demo
CSS:
And to distinguish it in writing, use
placeholder
: