This is a migrated thread and some comments may be shown as answers.

How to add style dynamically in JS?

3 Answers 123 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Kjell
Top achievements
Rank 1
Kjell asked on 23 Feb 2012, 08:46 PM
I am trying to set the text color for my autocomplete box on the fly.  I was able to get it working with the combobox thanks to your help in another thread, but having trouble applying that same logic to the autocomplete.

I grab the autocomplete box like this:
var cinput = $("#boxName").data("kendoAutoComplete");


cinput is an object, so at least it's not undefined, but I don't know if it's the correct object or if I am not setting the color properly (or both!).

But then it doesn't do anything when I try setting the color via any of the following (not all at once obviously):

cinput.css("color", "red");
cinput.color = "red";
cinput.style.color = "red";
cinput.foreground = "red";

but no luck.  I'm probably missing something fundemental due to my lack of JS experience.  Also without any intellisense it feels like I'm just taking shots in the dark, any guidance in that respect is greatly appreciated, in addition to a solution to my specifc question of course.

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 24 Feb 2012, 12:23 AM
Hi,

In that case cinput is an instance of the Kendo Autocomplete object. The latter does not have any of the API which you have tried. The full list of public methods can be seen here.

To change the color simply do this:

$("#boxName").css("color", "red");

This code is using the css jQuery method.

All the best,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Kjell
Top achievements
Rank 1
answered on 24 Feb 2012, 04:20 AM
Worked like a charm, thanks!
0
William
Top achievements
Rank 1
answered on 19 Apr 2012, 10:37 PM
Hi I have a question related to style but it can be set declaratively.  I want to set the background color of the suggestion dropdownlist.  Is there a CSS way of doing it?  And also the hover/focus state background color?  Thank you.
Tags
AutoComplete
Asked by
Kjell
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Kjell
Top achievements
Rank 1
William
Top achievements
Rank 1
Share this question
or