Lots of style-related jquery autocomplete questions (yow), but none that want to "match the parent input's style".
My Background
I'm a java/c++ programmer that has also had quite a bit of experience in JS... within PDF. PDF uses an entirely different object model from HTML, and I'm just starting to get used to it. I'm Quite New to jQuery.
I'd like my JQUI autocomplete control's style to match the corresponding input's style. Border style, font, font size, and so on.
The Question
This is for a form generation app that doesn't really speak CSS (as far as the users are concerned). Each field might have its own font & font size, background color, and so forth. I'd hope not, but Dammit Jim, I'm a programmer not a graphic designer! Not my department.
At any rate, this is programmatically generated HTML (done in Java), so some things that might be simple in hand-rolled markup are out of the question, and some things that would be all-but-impossible are fairly trivial.
Each input field has an ID, so creating the right selector is easy. What to do with that selector is the head-scratching part. Acquiring and parsing the style attribute in script at run time seems like Way Too Much Work. There's got to be a better way.
Ideally, it'd go something like this:
var stylesToCopy = $("#fieldID").???;
$(???).magicallyApplyStyles(stylesToCopy);
Looking at the markup generated by autocomplete (in firebug) I don't see an ID or anything to mark that particular UL as being "attached" to a given input. And I don't see anything added to the input to attach it the other way. Grr.
So what's a guy to do?
Further investigation: autocomplete()
returns the selected input, not the autocomplete control itself. Grr.
Hrrm...
Each input might have a different style (all set inline), so I don't think a class-based technique is going to work. That also means I need a selector that can pick out the right UL.
idea
A bit kludgy, but it'd work: Add a div with an ID to the body for each autocomplete, and use that as the appendTo
. The selector then becomes "first kid of ID such-n-so". I'm not sure how that will affect the autocomplete's positioning... maybe not at all. They're already in separate branches at different depths in the DOM tree.
$("#such-n-so:first-child").css(someAttr, someVal);
with css
and this li'l hack, I've got a working theory... but it seems like "the long way around". Hopefully one of you jQuery gurus can clue me in on something cleaner.