Get data attribute using switch using jQuery

I have the following html convertd for haml:

%input#insurance_isp_payment{ checked: "checked", type: "radio", name: "insurance_isp_payment", price: 27.22, value: "single"} 27,22 € 

And now I want to get this price value using the switch that is set. I tried something like this:

 $('input[name=insurance_isp_payment]:checked').data("price") 

But that does not work. How can I solve this problem?

+6
source share
1 answer

Try this: use attr() instead of data() to get the price value.

 var price = $('input[name="insurance_isp_payment"]:checked').attr("price"); alert(price); 
+11
source

Source: https://habr.com/ru/post/975059/


All Articles