Jump to content

class attribute selector for autocomplete field


Recommended Posts

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) {

	$('#editmain input').on('keypress', function(e) {
		if (e.which === 13) {
			var thisid = $(this).attr("termid");
			var col = $(this).attr("class");     // i use the class to identify the field and update it through ajax request
			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

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

  • Like 1
Link to comment
Share on other sites

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


or there is something special method for this?


thank u.

Edited by funbinod
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...