title: How to reference 'this' from a javascript call in a JSF component?
body: <pre><code>    &lt;h:commandLink id="#{id}" value="#{value}" action="#{actionBean.getAction}" onclick="alert(this);"/&gt;
  </code></pre>
  
  <p>In the previous simplified example, the 'this' keyword used in the Javascript function won't reference the generated A HREF element, but will reference to the global window, because JSF generates the following (simplified) code:</p>
  
  <pre><code>&lt;a onclick="var a=function(){alert(this)};var b=function(){if(typeof jsfcljs == 'function'){jsfcljs(document.forms['mainForm'],'generatedId,action,action','');}return false};return (a()==false) ? false : b();" href="#" id="generatedId"&gt;text&lt;/a&gt;
  </code></pre>
  
  <p>So because JSF wraps the user defined onclick in a function, this will point to the global window. I don't have access to the id of the element because my code is used in a generic component that can be used in loops etc. and I don't use backing beans (Facelets + JSF).</p>
  
  <p>So my question is, is there a way to access the A HREF element from within my onclick javascript function, without knowing the id?</p>