SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2011
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Changing the result display of jquery autocomplete

    I have a simple auto complete where I'd like to make changes to the result display.

    Here is the basic code.

    Code:
    	
    $('#names').autocomplete({
     source: "processor.php",
     minLength: 1				
    });
    This currently works fine, but I'd like to make the results alternatively highlight every row. So if the letter m was entered, this might appear:

    Maggie (highlighted in color 1 or with class 1)
    Margaret (highlighted in color 2 or with class 2)
    Mary (highlighted in color 1 or with class 1)

    Can someone tell me how I might accomplish this?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    I believe that CSS3 has an :nth-of-type(odd) selector, so you should be able to make good use of that to color every odd one, with another default color that would apply to the even ones.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2011
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are right, and that is what I thought to do too, but I don't know what to hook the css to. I don't know what class to apply it to (if there even is one). Do you have any thoughts here?

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ShinVe View Post
    Do you have any thoughts here?
    Do you have an example of the page as it currently is?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Zealot
    Join Date
    Nov 2011
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's not much to show. I am testing out jquery autocomplete before I integrate it into the actual site. It's just a totally bare bones page with jquery included and a form field.

    I can add anything to it you might suggest. I was hoping that jquery might have provided the means to do this though and I was just overlooking something I could hook my css onto, but I don't know.

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ShinVe View Post
    I was hoping that jquery might have provided the means to do this though
    Yes, jQuery provides a means to do that, with its :odd selector.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •