Slightly different behavior of $x in Oracle APEX 3.0

Just noticed a slightly different behavior of $x in Oracle APEX 3.0.

Probably many of you just use it to pass the id-string of an element (eg. $x(“P4_TEST”)) to this function to get the object of this field/div/… id, but you can also call it with an object and in that case the function will just return the object which has been passed in.

You may ask when do you need that? You need it if you write more generic JavaScript code where you have for example a function with the following example code

function getWhatEver(pField){  var vField = $x(pField);  // do what ever we want with vField};

If the caller has already the field object, then he just can pass it in and the function doesn’t have to do another lookup for the field

getWhatEver(vFieldVariable);

If the caller doesn’t have one, he can still call it with the id string

getWhatEver("P4_TEST");

and the $x function will do the necessary lookup.

The above described behavior still works for objects of node type 1 (Node.ELEMENTNODE), but with Oracle APEX 3.0 it doesn’t work if you pass in for example the window object, in that case the $x function will return false.

I had a function which can add/register events (eg. onkeypress, …) to each object, but in APEX 3.0 it failed when called with the window object.

So just be aware of this changed behavior!

One thought on “Slightly different behavior of $x in Oracle APEX 3.0

  1. Sorry about that , well not really :) .

    $x() has always supposed to be quick call for document.getElementById() with the extra functionality that it returns false instead of undefined if it ends up not returning a dom node. I actually added the dom node check for a couple of areas where we were accidentally passing in an object or an array and getting strange results.

    Carl

Comments are closed.