Skip to main content
1-Visitor
January 12, 2011
Question

checking element equality in javascript (rhino)

  • January 12, 2011
  • 2 replies
  • 1031 views
Hey everybody,

Let's say I do the following in Arbortext:

var document = Application.activeDocument;
var a = document.getElementById("stuff");
var b = document.getElementById("stuff");

So both a and b point to the same DOM element. Now, if I check their equality:

a == b

I get "false." Why is that? Shouldn't both variables contain references to the same object, and therefore be equal? Is there a simple way to check for element equality in javascript?

Note that when I do the same thing in a web browser, I get "true," like I expect.

Thanks,

James


    2 replies

    18-Opal
    January 12, 2011
    Hi James--

    Try a.equals(b).

    (FWIW, I think the behavior you're seeing is due to the way everything
    in Rhino is actually Java objects under the hood.)

    --Clay
    jsulak1-VisitorAuthor
    1-Visitor
    January 12, 2011
    Thanks, Clay, that works perfectly.

    -James