I have a type of input text that has to trigger a function on ‘keydown’. In order to identify this type of input I used an Id #autocomplete. So
$('#autocomplete').keydown(function(){
//function autocomplete
});
The problem is that I have this input twice in the same page, so jquery searches for the first id, and ignores the second one. (I am using an old jquery version, 1.3).
I solved it using $(“input#autocomplete”) instead. It works but is it a best practice? I guess Ids have to be unique. I could use class or name instead, but both have implications to other parts of code (class to the design, name to the server part the receives form parameters).
Which would be the best solution?
If you are in doubt for
classornamedue their affects ondesignandserver, you can always use attributes.and then select it like so
custom attributes that has
data-prefix are a standard in HTML5.