In my page i've got this :
<input type="hidden" data-name="adminvtech_tks_devis" data-type="string" data-displayvalue="181" data-value="181">
With Jquery I need to get the data-value (181 in this case) by searching by data-name (adminvtech_tks_devis in this case) in my HTML page.
How can I do that ?
I've tried this without success :
alert( $('*[data-name="adminvtech_tks_devis"]' ).data("data-value") );
But i'm getting undefined in my alert box instead of 181.
Thanks you very much.
CodePudding user response:
You need to omit the data- part in the key name:
alert( $('*[data-name="adminvtech_tks_devis"]' ).data("value") );
alert( $('*[data-name="adminvtech_tks_devis"]' ).data("value") );
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="hidden" data-name="adminvtech_tks_devis" data-type="string" data-displayvalue="181" data-value="181">
Check out the documentation.