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

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -