javascript - Get data value from .click by class -


This code will give the name of the right square, but the right data will not be a valid mount. This will only be output: undefined.

  $ (".prod_amount_add"). Click (function () {var rowAmount = 0; var datavalid = $ (this) .attr ('data-validamount'); Console.log (datavalid); console.log ($ (this) .attr ('class' ));}); & Lt; Div class = "prod_amount_add" & gt; & Lt; Img src = "icon / add page" width = "16" height = "16" alt = "plus 1" data-valid name = "1" & gt; & Lt; / Div & gt;  

The attribute is on your img , not your < Code> .prod_amount_add div, so you can do the $ (this) .find ('img'). Attr ('data-validamount');


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -