0

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/

1 Answer 1

5

Instead of

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

Use

$('#hello, #hello2')

WORKING DEMO

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.