diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index a8b2895d6b..cedea8354e 100644 --- a/types/jquery/index.d.ts +++ b/types/jquery/index.d.ts @@ -699,6 +699,14 @@ interface JQueryCoordinates { top: number; } +/** + * The interface used to specify the properties parameter in css() + */ +type cssPropertySetter = (index: number, value?: string) => string | number; +interface JQueryCssProperties { + [propertyName: string]: string | number | cssPropertySetter; +} + /** * Elements in the array returned by serializeArray() */ @@ -1707,7 +1715,7 @@ interface JQuery { * @param properties An object of property-value pairs to set. * @see {@link https://api.jquery.com/css/#css-properties} */ - css(properties: Object): JQuery; + css(properties: JQueryCssProperties): JQuery; /** * Get the current computed height for the first element in the set of matched elements. diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index d2d58aa2a2..4b6fc4e0db 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -1065,6 +1065,9 @@ function test_css() { $('div.example').css('width', function (index) { return index * 50; }); + $('div.example').css('width', function (index, style) { + return style.length > 0 ? style : index * 50; + }); $("p").mouseover(function () { $(this).css("color", "red"); });