mathiasbynens / jquery-placeholder

A jQuery plugin that enables HTML5 placeholder behavior for browsers that aren’t trying hard enough yet
https://mths.be/placeholder
MIT License
3.98k stars 1.34k forks source link

Placeholder not showing when the elements are loaded from Ajax #264

Closed ruchiratrivedi closed 9 years ago

ruchiratrivedi commented 9 years ago

When I add the ajax response to a div on the page, the placeholder text does not show for the the textbox and textarea present in the ajax response. I have to refresh the page. I tried calling $('input, textarea').placeholder(); after ajax success. But it doesn't work.

emilhem commented 9 years ago

Make sure that placeholder is run after the AJAX return have rendered/been placed in the DOM.

thereisnobugs commented 9 years ago

Try this. It works for me

$.ajax().success(function (response) {
           $(%YOUR_CONTENT%).find('input').placeholder();
        });
amerikan commented 9 years ago

@ruchiratrivedi you must recall the placeholder since it doesn't know about "future" DOM elements.