Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Edit:</strong> Revisiting your question, it looks like the point I focused on may not be exactly the problem. I won't delete it because it is a valid issue with the code you posted. The issue with the textarea value not being queried or modified is most likely because you're adding the <code>textarea</code> after the DOM has loaded. You should be able to use a <a href="http://api.jquery.com/live/" rel="nofollow">jquery.live()</a> event on your table or the delegate event at the end of this post. Both are valid for any current or future DOM elements. These are a life saver when performing any DOM manipulation or ajax-based HTML updates. This would also explain why you're able to perform the operation in the console and not in the code.</p> <p><strong>Original answer:</strong> I'm not sure if this will help fully, but I think what is preventing your code from executing is:</p> <pre><code>if(block || !($(this).attr('incomplete'))) return; </code></pre> <p>When your table cells don't have that attribute, you're actually executing:</p> <pre><code>if( block || !(undefined) ) return; </code></pre> <p>Which will always be true because <code>!(undefined)</code> is true. You most likely want to be forcing a boolean value:</p> <pre><code>if( block || !!(undefined) ) return; </code></pre> <p>This is fine if you are only expecting <code>undefined</code> and any text value. A better way to modify this condition is to explicitly check the value you're expected (and I'm assuming you expect to be "true"):</p> <pre><code>if(block || ($(this).attr('incomplete') === "true") ) return; </code></pre> <p><strong>Suggestion:</strong></p> <p>One suggestion I would make is instead of inlining the onclick function, use HTML5 data-* attributes to store your data and perform the code in one place. This helps keep JavaScript in a single place and doesn't mix it throughout the HTML.</p> <p>For example, you can generate a <code>data-id</code> attribute for each table cell and mark your table row editable with <code>data-edit-cell="true"</code></p> <pre><code>&lt;table&gt; &lt;tr data-edit-cell="true"&gt; &lt;td data-id="1"&gt;cell one&lt;/td&gt; &lt;td data-id="2"&gt;cell two&lt;/td&gt; &lt;td data-id="3"&gt;cell three&lt;/td&gt; &lt;td data-id="4"&gt;cell four&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;​ </code></pre> <p>Then, a second suggestion, instead of binding a click event to each cell , you can bind an event to the row using <a href="http://api.jquery.com/delegate/" rel="nofollow">jquery.delegate()</a>, which watches for bubbling events (<em>click</em>) of a child defined by a selector (<em>td</em>):</p> <pre><code>var block = false; $('tr[data-edit-cell=true]').delegate('td', 'click', function() { if (block || $(this).attr('incomplete') === "true" ) return; //only one is allowed block = true; console.log('clicked: ' + $(this).attr('data-id')); });​ </code></pre> <p>I've created a jsfiddle <a href="http://jsfiddle.net/jimschubert/Daur8/1/" rel="nofollow">here</a> so you can check this code out.</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.
 

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