jQuery focus blur pass parameter

javascript, jquery, jquery-events

Solution

Looks like the question is about the passing data into the .blur or .focus event. per jQuery API - http://api.jquery.com/blur/

blur( [eventData ], handler(eventObject) )

So if you want to pass data - you can send a parameter to event - which will appear as data in event object.

see this fiddle for more info

http://jsfiddle.net/dekajp/CgP2X/1/

var p = {
    mydata:'my data'
};

/* p could be element or whatever */
$("#tb2").blur(p,function (e){
    alert('data :'+e.data.mydata);
});

Problem

I can't seem to access the variable `defaultValue` down in my `.blur()` function. I've tried various stuff but with no luck. So far I only get an empty object. What's wrong? ``` jQuery(document).ready(function(){ jQuery('#nameInput, #emailInput, #webInput').focus(function(){ var defaultValue = jQuery(this).val(); jQuery(this).val(""); }) .blur(function(defaultValue){ if(jQuery(this).val() == ""){ jQuery(this).val(defaultValue); } }); }); ```

Original source