title: JQuery selector of script tag calling from
body: <p>i have the following html output of a tool thats i'm developing:</p>
  
  <pre><code>&lt;button&gt;a&lt;/button&gt;
  &lt;script&gt;$('what to wrtie here to select the previous button element?').click(function(){alert ('a clicked !');});&lt;/script&gt;
  &lt;button&gt;b&lt;/button&gt;
  &lt;script&gt;$('same here').click(function(){alert ('b clicked !');});&lt;/script&gt;
  </code></pre>
  
  <p>i need the selector in each <code>script</code> tag to select the previous element.
  using <code>id</code> selector cant be applied since the tool don't generate ids for elements.</p>
  
  <p>thanks.</p>
  
  <p><strong>ANSWER:</strong></p>
  
  <pre><code>$('script').last().prev().click(...
  </code></pre>
  
  <p>as Niklas said the current executed script is the last one in the list</p>