convert htmlelement to string for comparison javascript -
I am using a function that receives a target element id on onclick. For example, if I click on the text element which has the 'help' ID.
var click = (e & e.target) || (Event & amp; event. SrcElement); In the
var click the "Help" ID is included in the referee.
I want to compare var click with string 'help' if I
if (click == 'about') {anything}
Comparison does not work because var click is not a string. When I use the warning (click) to debug, it clicks as "object HTMLElement".
How would you compare that ID is derived from the 'help' var click?
P> But this will give a long statement. Also
if click on the document.getElementById ('help')
, then how do I create word by adding the word "div" to the word click
Basically, I want to use the same task to generate clickable dynamic responses for each element, and not to create a separate function for each element.
if (click.id == 'help') {var Link = click; Var divid = click.id + 'div'; Var div = document.getElementById (partition); Warning (div.id); // helpdiv string}
TIA for all your help.
line:
var click = (e and e .target) || (Event & amp; event. SrcElement);
is not getting the element
var id = click.getAttribute ('id'); Warning (id);
Or simply:
var id = click.id; Warning (id);
Then your status is now:
if (id == 'about') {anything}
<>and
if (id == document.getElementById ('help')) {something}
Comments
Post a Comment