Reputation: 4066
Here is my attempt to add a listener which clears the placeholder on focus for every input box. Are there any errors evident in my code?
var $inputs = $('.add-item-form :input');
$inputs.each(function() {
var that = $(this);
that.focus(function() {
that.attr('placeholder') = '';
})
});
Upvotes: 1
Views: 749
Reputation: 13753
Use
that.attr('placeholder','');
insted of
that.attr('placeholder')='';
full code
var $inputs = $('.add-item-form :input');
$inputs.each(function() {
var that = $(this);
that.focus(function() {
that.attr('placeholder','');
})
});
as gdoron said, no need to cache dom objects, you can use gdoron's code much cleaner code
Upvotes: 2
Reputation: 481
$('.add-item-form:input').focus(function() {
$(this).attr('placeholder', '');
});
as gdoron suggested in addition you have to delete the extra space on jquery selector
this: '.add-item-form:input'
instead of: '.add-item-form :input'
Upvotes: 0
Reputation: 150273
$('.add-item-form :input').focus(function() {
$(this).attr('placeholder', '');
});
Upvotes: 2
Reputation: 87073
$('.add-item-form :input').each(function() {
var that = $(this);
that.on('focus', function() {
that.attr('placeholder','');
});
});
Upvotes: 0