methuselah
methuselah

Reputation: 13216

Passing through multiple ids on jQuery function

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

Answers (1)

casraf
casraf

Reputation: 21694

Instead of

$('#hello', '#hello2')

Use

$('#hello, #hello2')

WORKING DEMO

Upvotes: 5

Related Questions