Dear All,
I am digging myself into a hole here over what I think should be a very simple bit of code. Perhaps I have been looking at too long have have lost my way.
Either way some direction would be most welcome.
I want to use a regular expression to differentiate between elements. So I am assuming (bad word that) that I need to convert a reference to an element intotext before I can test it using a regular expressions.
i.e
var myString "<a id=“ml2” ";
var myExpr1 = /ml2/;
console.log(“test text”,myExpr1.test(myString)); // displays true
whereas
var myElement = document.getElementById(“ml2”);
console.log(“element”,myElement); // displays element<a id=“ml2” href=“http://localhost/xxxxhome/search.html”>
console.log(“test element”,myExpr1.test(myElement)); displays false
so I am assuming (ekk there’s that word again) when the myElement is output or referenced by any other code it is not as a string.
Therefore I want to know how to make it into a string. toString(myElement); returns [object Window] which was not what I was expecting
==================================================================================================
I am also very confused with equality of elements:-
var myElement = document.getElementById(“ml2”);
myElement.onmouseout = onMouseOut;
function onMouseOut(event){
console.log("element",myElement); // displays element<a id="ml2" href="http://localhost/xxxxhome/search.html">
console.log("target",event.target); // displays target<a id="ml2" href="http://localhost/xxxxhome/search.html">
if (myElement != event.target){
console.log("not equal"); // always unequal
} else {
console.log("equal");
}
}
Why are they always unequal they report identically is it something like they are difference instances of the same reference???