views:

104

answers:

2

Hi,

Im using firebug to debug jquery and in the dom tab i can see all the vars and arrays in there.

How do I access the different arrays and vars in the dom?

Cheers Kealt text

I cannot access these object items, even though firefox lists them, i have sitems in the top level of the dom, i also have sitems within the parent variable.

a lot of head scratching happening here, would be grateful for any help :)

A: 

If it's an array you should access it as an array by referencing the index in the Array you are trying to access.

alert(sitems[1]); 

If it's an object you can reference by using the "key" for the property or method of the object you are trying to access:

alert(sitems["keyName"]);

Likewise some of the stuff you'll see in the DOM tab are actually references to methods and objects within the DOM, so if you're going to call them or reference them you need to do so based on their type, or you may even need to provide arguments to them in order to get a response.

It's giving 'undefined' because you can't output the contents of an Array just by calling its name.

jduren
Javascript does not have relational arrays. In your first example `sitems` is a Javascript Object but not an Array Object..... You can test this by checking for `sitems.length` which will only be defined for an array. ==> http://jsfiddle.net/Qt3jN/
Peter Ajtai
yes i tried all of these and more, i have listed an image to show my problem above
Ke
If its a straight variable you should be able to do alert(sitems); if it's an array call it with alert(sitems[0]); (where zero is the index of the array you are trying to access) if it's an object try alert(sitems["methodOrProperty"]); and provide the method or property you are trying to access in the object. If it's in the root of the DOM you shouldn't have to add document.body or anything else to reference it (at least in the latest Firebug).
jduren
i have provided everything in the image i gave above. ive tried all of these and none of them work, maybe javascript doesnt work!
Ke
Have you tried from the FireBug Console? The item may only accessible from there.
jduren
+1  A: 

Looks like you want to access a user defined property, since these are not properties of the DOM ( Firebug Wiki DOM panel page. ), I don't think you can access them directly through your page, but you can access them through the Firebug console.

Simply type the name of the property into the command line of the Console... the part after >>> on the very bottom.

In your case you would type something like: sitems[0] and hit enter.


To access properties of the DOM... take a look at the DOM exploration page for Firebug.

To see how to access properties, functions, or constants of the DOM, check what you're interested in in the DOM tab.

Then you can "follow the bread crumbs" to access properties directly. Global properties are attached to window, so you don't need to include window: alt text

Make sure to right click on things and explore the context menu, especially if you start looking at functions.

Peter Ajtai
ive done all of this. Ive tried every single variation i can think of for sitems, it just wont print out. i can see it in the dom, but i cant access it. i added a screenshot to my question to show you whats happening
Ke
@Ke - How did you try to access it? `alert(sitems.0.display);` ? `alert(sitems[0].display);`? ... Are you sure it's part of the DOM and not user created?
Peter Ajtai
yes its user created, (i tried all those variations shown and more) how do i access the user created ones then? is it different? cheers for taking the time to point me in the right direction :)
Ke
@Ke - I think you can only access those through the Firebug console. Edited answer....
Peter Ajtai
i am including flexigrid to send some parameters to it, the parameters can be resent by click on a column for instance and this posts to the script again. is there really no way that i can access the data thats posted to the flexigrid? i cant find anything under sitems[0] but i can find under sitems becaus it exists in firebug
Ke
@Ke - Sounds like this is a more complicated issue. Maybe you should create a question about your flexigrid problem.
Peter Ajtai