Bug Tracker

Modify

Ticket #8586 (closed bug: worksforme)

Opened 2 years ago

Last modified 2 years ago

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:
Blocking: Blocked by:

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

comment:1 follow-up: ↓ 2 Changed 2 years ago by addyosmani

  • Owner set to stevensalter42@…
  • Status changed from new to pending

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 2 years ago by stevensalter42@…

  • Status changed from pending to new

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 follow-up: ↓ 4 Changed 2 years ago by rwaldron

  • Status changed from new to closed
  • Resolution set to worksforme
  • Component changed from unfiled to effects

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 2 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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.