Note that there are some explanatory texts on larger screens.

plurals
  1. POx-editable how to get the id of clicked element
    text
    copied!<p>I am new to x-editable and jQuery so I am having an issue understanding how to get the "id" of a clicked element using x-editable, hopefully someone can help. </p> <p>I have several links on my page within a div called #line_item_unit_cost. </p> <pre><code> &lt;div id="line_item_unit_cost"&gt; &lt;a id="1"&gt;link&lt;/a&gt; &lt;a id="2"&gt;link&lt;/a&gt; &lt;a id="3"&gt;link&lt;/a&gt; &lt;a id="4"&gt;link&lt;/a&gt; &lt;a id="5"&gt;link&lt;/a&gt; &lt;/div&gt; </code></pre> <p>When I click on one of the links I am firing an x-editable script that will allow me to do an inline edit. The issue I am having is that I need to pass in which line item I am working on so that I can update my db. I dont know how (or I am doing it wrong) to access that "id" of the link I click. </p> <p>Here is my script: </p> <pre><code> $('#line_item_unit_cost a').editable({ validate: function(value) { if($.trim(value) == '') return 'This value is required.'; }, type: 'text', url: '/post', pk: {{ purchaseOrder.id }}, title: 'Enter Value', params: { purchaseOrderId : {{ purchaseOrder.id }} , lineId : $(this).attr("id"), text: 223 }, ajaxOptions: { dataType: 'json' }, success: function(response, newValue) { } }); </code></pre> <p>This line: lineId : $(this).attr("id") gives me a null value. </p> <p>If I use lineId : $("#line_item_unit_cost a").attr("id") keeps pulling up the first instance on the page's "id", not the one that is being edited.</p> <p>Anyone know how to get the id of the link that I clicked using x-editable? </p> <p>Thanks so much!!!</p>
 

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