Bug Tracker

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#8391 closed bug (duplicate)

scrollTop, scrollLeft setters break chaining when selector doesn't match any elements

Reported by: fred.mol@… Owned by:
Priority: high Milestone: 1.next
Component: offset Version: 1.5.1
Keywords: Cc:
Blocked by: Blocking:

Description

The following line throws a javascript error:

$('.does-not-exist').scrollTop(0).scrollLeft(0);

The reason is that both scrollTop and scrollLeft always return null when the selector doesn't match any elements. They should only return null when used as getter (i.e. called without any arguments) Test case: http://jsfiddle.net/QZ6nH/1/

Change History (5)

comment:1 Changed 9 years ago by dmethvin

Status: newopen

Yep, seems inconsistent.

comment:2 Changed 9 years ago by dmethvin

Component: unfiledattributes
Milestone: 1.next1.6
Priority: undecidedlow

comment:3 Changed 9 years ago by jitter

Component: attributesoffset
Milestone: 1.61.next
Priority: lowhigh
Resolution: duplicate
Status: openclosed

comment:4 Changed 9 years ago by jitter

Duplicate of #7931.

comment:5 Changed 9 years ago by anonymous

Here's a pull request with the fix: https://github.com/jquery/jquery/pull/171

Note: See TracTickets for help on using tickets.