Reputation: 3214
I am trying to implement jQuery UI Autocomplete behaviour in a Text Box.I have followed an example and It works fine. But some syntax making me confused. Here is the code snippet:
<div>
@Html.LabelFor(a => a.name)
@Html.TextBoxFor(a => a.name, new { data_autocomplete_url = Url.Action("Autocomplete") })
</div>
<script type="text/javascript">
$(document).ready(function () {
$('[data-autocomplete-url]')
.each(function () {
$(this).autocomplete({
source: $(this).data("autocomplete-url")
});
});
});
</script>
I am declaring the TextBox to have an attribute data-autocomplete-url
. But in the jQuery UI autocomplete function I am using only autocomplete-url
without data-
prefix. How this works ?
Upvotes: 1
Views: 99
Reputation: 10040
That .data()
method already knows that you are calling the value of data-*
attribute.
And does not require preceding data-
before the name of attribute when calling it.
Upvotes: 2