Jump to content
funbinod

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) {
				$(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..

Share this post


Link to post
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

Share this post


Link to post
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

$("input[data-class='resultdate'"]

or there is something special method for this?

 

thank u.

Edited by funbinod

Share this post


Link to post
Share on other sites

It is an attribute, so the usual attribute selector will work.

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...