Skip to main content

Bug Tracker

Side navigation

#8586 closed bug (worksforme)

Opened March 22, 2011 01:54PM UTC

Closed March 30, 2011 04:38PM UTC

Last modified April 03, 2011 03:19PM UTC

contents().hide() results in javascript error, does not hide text nodes

Reported by: stevensalter42@hotmail.com Owned by: stevensalter42@hotmail.com
Priority: undecided Milestone: 1.next
Component: effects Version: 1.5.1
Keywords: Cc:
Blocked by: Blocking:
Description

If you have a table cell with whitespace or text, and you try to do:

 $cell.contents().hide();

you will get a Javascript error:

Cannot set property 'display' of undefined

The reason is this loop on line 7486 of jquery-1.5.1.js:

  for ( i = 0; i < j; i++ ) {
    this[i].style.display = "none";
  }

Incidentally, I tried simply adding a check to avoid the error:

for ( i = 0; i < j; i++ ) {
    if (this[i] != undefined && this[i].style != undefined)
      this[i].style.display = "none";
}

This prevents the error from occurring, however, it doesn't solve the problem, since the text node is not hidden.

Attachments (0)
Change History (4)

Changed March 22, 2011 03:12PM UTC by addyosmani comment:1

owner: → stevensalter42@hotmail.com
status: newpending

Thanks for submitting a ticket to the jQuery Bug Tracker. So that we can assist you further, please also provide us with a minimal test case on http://jsfiddle.net that reproduces the issue you're experiencing.

Changed March 22, 2011 08:34PM UTC by stevensalter42@hotmail.com comment:2

status: pendingnew

Replying to [comment:1 addyosmani]:

Thanks for submitting a ticket to the jQuery Bug Tracker. So that we can assist you further, please also provide us with a minimal test case on http://jsfiddle.net that reproduces the issue you're experiencing.

http://jsfiddle.net/kK3W7/

Changed March 30, 2011 04:38PM UTC by rwaldron comment:3

component: unfiledeffects
resolution: → worksforme
status: newclosed

This is not a jQuery "bug", as hide() operates on matched elements (contents returns elements, text nodes and comment nodes), which is documented here: http://api.jquery.com/hide

The correct way to hide cell "contents"

http://jsfiddle.net/rwaldron/kK3W7/2/

Changed April 03, 2011 03:19PM UTC by anonymous comment:4

Replying to [comment:3 rwaldron]:

This is not a jQuery "bug", as hide() operates on matched elements (contents returns elements, text nodes and comment nodes), which is documented here: http://api.jquery.com/hide The correct way to hide cell "contents" http://jsfiddle.net/rwaldron/kK3W7/2/

I understand that there are other ways to hide contents that work. I believe the fact that contents().hide() can generate a javascript error is a problem. Even if fixing the effect isn't a priority, I would expect it to hide what it can and ignore the rest without error.