Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This won't work:</p> <pre><code>$('#myElement').click(ElementClicked($(this))); </code></pre> <p>This is executing the function <code>ElementClicked()</code> with whatever <code>this</code> is at the time of writing, and binds the <strong>return value</strong> of <code>ElementClicked()</code> to the <code>click</code> event. Which in this case is nothing.</p> <p>You'll need to <em>pass</em> a function to a click event, like so:</p> <pre><code>$('#myElement').click(function () { ElementClicked($(this)); }); </code></pre> <p>This makes a(n anonymous) function, which will be bound to the <code>click</code> event, and the function calls <code>ElementClicked()</code> when run, passing <code>this</code>. The function <code>ElementClicked</code> can be defined as:</p> <pre><code>function ElementClicked(elem) { elem.addClass('clicked'); } </code></pre> <p>As you will notice though, <code>this</code> inside the function that is bound to the event will be the clicked element. So instead of making a function wrapper that calls a function passing the element, you can just abbreviate it like so:</p> <pre><code>$('#myElement').click(ElementClicked); function ElementClicked() { $(this).addClass('clicked'); } </code></pre> <p>Notice that the function is passed to <code>click()</code> like a variable instead of being executed immediately, because there are no brackets <code>()</code> following it.</p> <p>And BTW, you probably mean <code>addClass</code> instead of <code>addCss</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload