diff --git a/jquery/jquery-tests.ts b/jquery/jquery-tests.ts index c96468327d..5105dc54aa 100644 --- a/jquery/jquery-tests.ts +++ b/jquery/jquery-tests.ts @@ -1642,6 +1642,33 @@ function test_height() { }); } +function test_width() { + // Returns width of browser viewport + $(window).width(); + + // Returns width of HTML document + $(document).width(); + + function showWidth(ele, w) { + $("div").text("The width for the " + ele + " is " + w + "px."); + } + $("#getp").click(function () { + showWidth("paragraph", $("p").width()); + }); + $("#getd").click(function () { + showWidth("document", $(document).width()); + }); + $("#getw").click(function () { + showWidth("window", $(window).width()); + }); + + var modWidth = 50; + $("div").one("click", function () { + $(this).width(modWidth).addClass("mod"); + modWidth -= 8; + }); +} + function test_hide() { $('.target').hide(); $('#clickme').click(function () { diff --git a/jquery/jquery.d.ts b/jquery/jquery.d.ts index 5f42dd1af0..88dcde5f0a 100644 --- a/jquery/jquery.d.ts +++ b/jquery/jquery.d.ts @@ -1041,10 +1041,46 @@ interface JQuery { scrollTop(): number; scrollTop(value: number): JQuery; + /** + * Get the current computed width for the first element in the set of matched elements. + */ width(): number; + /** + * Set the CSS width of each element in the set of matched elements. + * + * @param value An integer representing the number of pixels, or an integer along with an optional unit of measure appended (as a string). + */ width(value: number): JQuery; + /** + * Set the CSS width of each element in the set of matched elements. + * + * @param value An integer representing the number of pixels, or an integer along with an optional unit of measure appended (as a string). + */ width(value: string): JQuery; - width(func: (index: any, height: any) => any): JQuery; + /** + * Set the CSS width of each element in the set of matched elements. + * + * @param func A function returning the width to set. Receives the index position of the element in the set and the old width as arguments. Within the function, this refers to the current element in the set. + */ + width(func: (index: number, width: number) => number): JQuery; + /** + * Set the CSS width of each element in the set of matched elements. + * + * @param func A function returning the width to set. Receives the index position of the element in the set and the old width as arguments. Within the function, this refers to the current element in the set. + */ + width(func: (index: number, width: string) => string): JQuery; + /** + * Set the CSS width of each element in the set of matched elements. + * + * @param func A function returning the width to set. Receives the index position of the element in the set and the old width as arguments. Within the function, this refers to the current element in the set. + */ + width(func: (index: number, width: string) => number): JQuery; + /** + * Set the CSS width of each element in the set of matched elements. + * + * @param func A function returning the width to set. Receives the index position of the element in the set and the old width as arguments. Within the function, this refers to the current element in the set. + */ + width(func: (index: number, width: number) => string): JQuery; // Data clearQueue(queueName?: string): JQuery;