Prady Prady - 1 year ago 131
Javascript Question

what does [object Object] mean?

I am trying to alert a returned value from a function and i get this in the alert

[object Object]

here is the javascript code

<script type="text/javascript">
$(function ()
var $main = $('#main'),
$1 = $('#1'),
$2 = $('#2');

$2.hide(); // hide div#2 when the page is loaded

$ ()

$('#senddvd').click(function ()
var a=whichIsVisible();

function whichIsVisible()
if (!$':hidden')) return $1;
if (!$':hidden')) return $2;



whichIsVisible is the function which i am trying to check on

Answer Source

The default conversion from an object to string is "[object Object]".

As you are dealing with jQuery objects, you might want to do


to print the element's ID.

As mentioned in the comments, you should use additional tools like Firebug for Firefox to introspect objects by doing console.log(whichIsVisible()) instead of alert (no need for extra tools in Chrome or Safari).

Sidenote: IDs should not start with digits.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download