14

What to do when after all probing, a reportedly valid object return 'undefined' for any attribute probed? I use jQuery, $('selector').mouseover(function() { }); Everything returns 'undefined' for $(this) inside the function scope. The selector is a 'area' for a map tag and I'm looking for its parent attributes.

sblundy
  • 60,628
  • 22
  • 121
  • 123
Florin
  • 1,379
  • 3
  • 16
  • 21

3 Answers3

31

Your question is a bit vague, so maybe you can provide more details?

As for finding out about an object and the values of its properties, there are many ways to do it, including using Firebug or some other debug tools, etc. Here is a quick and dirty function that might help get you started until you can provide more details:

function listProperties(obj) {
   var propList = "";
   for(var propName in obj) {
      if(typeof(obj[propName]) != "undefined") {
         propList += (propName + ", ");
      }
   }
   alert(propList);
}

That will display a list of the properties of the object that you pass it that are not undefined.

Hope that helps...

Jason Bunting
  • 58,249
  • 14
  • 102
  • 93
  • In Firefox you can do simply call toSource( ) on an object: var o = { "moo": "cow", "woof", "dog" }; o.toSource( ); //"({moo:"cow", woof:"dog"})" – Bjorn Feb 26 '10 at 13:29
  • 2
    Or, for that matter, use the now-built-in JSON object and call stringify() on it as well - the results are a bit different, but not much. https://developer.mozilla.org/En/Using_native_JSON – Jason Bunting Mar 03 '10 at 22:39
  • 3
    @Lothar - Actually, to some limited extent, it does. Introspection allows for finding out the methods and properties of an object, as does the function I provided above. Are you merely being pedantic about the fact that we are not referring specifically to Java? If so, well... – Jason Bunting Sep 23 '12 at 06:30
0

Is selector the name of the element? If so then you should reference it as:

$('area#selector')

or

$('#selector')

otherwise it will attempt to look for the (non-existent) "selector" HTML tag and, obviously, not find it.

tvanfosson
  • 524,688
  • 99
  • 697
  • 795
  • Yes, the correct notation was used: $('#myarea') where the id='myarea' for the area tag. Thanks. – Florin Nov 30 '08 at 06:05
0

Though this answer is a bit late, I'd still recommend checking out these links:

http://www.webweavertech.com/ovidiu/weblog/archives/000317.html
http://www.syger.it/Tutorials/JavaScriptIntrospector.html

Michael Myers
  • 188,989
  • 46
  • 291
  • 292