funbinod Posted March 12, 2018 Share Posted March 12, 2018 hello all! i've a autocomplete field which has a class attribute 'resultdate'. and i want to select that element using its class attribute. but when i try to catch that field i found that the autocomplete specified class is also added to it. $(function() { $('.resultdate').autocomplete({ ////// this is an input field and i've many input fields with different class names. source: "selectdate.php", minLength: 0, autoFocus: false, select: function(e) { $(this).val($(this).substr(0,10)); } }).focus(function(){ $(this).autocomplete("search"); }) }); $('#editmain input').on('keypress', function(e) { if (e.which === 13) { e.preventDefault(); $("#msg").empty().hide(); var thisid = $(this).attr("termid"); var col = $(this).attr("class"); // i use the class to identify the field and update it through ajax request alert(col); var newvalue = $(this).val(); editterm(thisid, col, newvalue); } }) for other plain input field (means the inputs that donot have any autocomplete function) it works fine. but for autocomplete field (for example class='resultdate') this gives 'resultdate ui-autocomplete-input' as its class please guide how can i select the only class that i,ve specified? thank u in advance.. Link to comment Share on other sites More sharing options...
Ingolme Posted March 12, 2018 Share Posted March 12, 2018 When you use jQuery and its plugins they often put additional classes on the elements. See if any of the class methods in jQuery help solve your problem, if not then you probably should use data attributes instead of the class attribute to store data. Here's how data attributes are defined: <element data-something="value1" data-somethingelse="value2"> In jQuery you can access the value of data attributes using the data() method: http://api.jquery.com/data/#data-key 1 Link to comment Share on other sites More sharing options...
funbinod Posted March 13, 2018 Author Share Posted March 13, 2018 (edited) very good suggestion. i didnot know about data attribute in html 5 and jquery. your guidance made me clear almost all about data- attribute. but one thing more. i got confused using selector for this attribute. shall i have to use, in jquery $("input[data-class='resultdate'"] or there is something special method for this? thank u. Edited March 13, 2018 by funbinod Link to comment Share on other sites More sharing options...
Ingolme Posted March 13, 2018 Share Posted March 13, 2018 It is an attribute, so the usual attribute selector will work. 1 Link to comment Share on other sites More sharing options...
dsonesuk Posted March 13, 2018 Share Posted March 13, 2018 IF you do it correctly $("input[data-class='resultdate'"] Should be $("input[data-class='resultdate']") 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now