It is possible to pass variables to a jquery event using custom html attribute
<input type="text" id="custominput" data-ajax-id="1">
$("#custominput").on("click", function() {
alert($(this).data("ajax-id"));
}
I tried using the same method for a spinner, but this isn't working. I would like to set max through a html custom attribute
<input type="text" id="spinnercount" class="form-control ui-spinner-input" name="groupcount" value="10" data-ajax-max="10" role="spinbutton">
$("#spinnercount").spinner({
max: $(this).data("ajax-max")
})
Does anyone know how to do this ?
Thanks
"this" is not what you expect it to be.
in your first example you are in the scope of a function. jquery sets the calling element(s) to be "this" there.
in your 2nd code you are in the global scobe.
try:
var spinnerCountElement = $("#spinnercount");
spinnerCountElement.spinner({
max: spinnerCountElement.data("ajax-max")
})