Reputation: 13216
How do you pass through multiple elements on a jQuery function?
This is my code so far:
HTML
<textarea id="hello">This is the default text</textarea>
<input id="hello2" value="This is another text box">
JavaScript
$(function() {
$('#hello', '#hello2').each(function() {
$.data(this, 'default', this.value);
}).focus(function() {
if (!$.data(this, 'edited')) {
this.value = "";
}
}).change(function() {
$.data(this, 'edited', this.value != "");
}).blur(function() {
if (!$.data(this, 'edited')) {
this.value = $.data(this, 'default');
}
});
});
Demo: http://jsfiddle.net/eJP9C/252/
Upvotes: 0
Views: 52