I have searched and found multiple answers simply stating to wrap my function in a click handler, although I want it to run on page load, or once my javascript has finished inserting all the html.
I have a whole page that's dynamically created. I'm using this snippet to fix Placeholders for IE. It does work, although not with live created elements.
$(document).ready(function(){
// Placeholder Fix for IE < 9
$("[placeholder]").each(function() {
var val = $(this).attr("placeholder");
if ( this.value === "" ) {
this.value = val;
}
$(this).focus(function() {
if ( this.value == val ) {
this.value = "";
}
}).blur(function() {
if ( $.trim(this.value) === "" ) {
this.value = val;
}
});
});
// Clear default placeholder values on form submit
$('form').submit(function() {
$(this).find("[placeholder]").each(function() {
if ( this.value == $(this).attr("placeholder") ) {
this.value = "";
}
});
});
});
I'm adding in form elements with js, example:
$('body').append('<input type="text" placeholder="placeholdertext" />');
Can someone advise how to fix this problem?
Shannon