Bug Tracker

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#8586 closed bug (worksforme)

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

Reported by: stevensalter42@… Owned by: stevensalter42@…
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.

Change History (4)

comment:1 Changed 9 years ago by addyosmani

Owner: set to stevensalter42@…
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.

comment:2 in reply to:  1 Changed 9 years ago by stevensalter42@…

Status: pendingnew

Replying to 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/

comment:3 Changed 9 years ago by Rick Waldron

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/

comment:4 in reply to:  3 Changed 9 years ago by anonymous

Replying to 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.

Note: See TracTickets for help on using tickets.