Get an element's ID and compare it to a string OR another ID
dom-events, javascript
Solution
if(elemid = document.getElementById('myid').id)
{
...
}
You need to compare it using `==`. A single `=` is assign.
Also `document.getElementById('myid').id` is completely useless. You are specifying the `id` directly and then attempt to return it.
As a simple test to show you how to compare an element.
<input type="text" id="hello" class="test" />
var element = document.getElementsByClassName("test")[0].id;
if (element === "hello") {
alert("Working");
}
http://jsfiddle.net/ckJP9/
Problem
How can I get the ID of an element and compare it to a string OR another id ? What I would like to do exactly is make a condition that would get the element's ID and compare it to a certain string or another element's ID. I have this piece of code right now to compare my id to another id (which obviously doesn't work): ``` function Something(elemid) { if(elemid == document.getElementById('myid').id) { ... } } ``` Or this piece of code to compare to a string (doesn't work either): ``` if(elemid == "mystring") { ... } ``` This is a simple problem, but still, I can't seem to find anything around here or even on other websites that would be what I am searching for. I can't use any JQuery whatsoever, so any Javascript only anwser would be really appreciated.