jQuery tries to access the .style attribute of text tags
|Reported by:||ryangreenberg||Owned by:|
When constructing elements from HTML using $([html]), jQuery will sometimes include whitespace nodes. .hide and .show try to manipulate the non-existant .style property of these whitespace nodes resulting in an error.
This error occurs on Firefox 3.5 and Safari 4 for Mac. See a demonstration of this bug at http://jsbin.com/avisi/6. Here is a test case:
<body> If you don't see "Hi" and "Hello", an error occurred. <div id="project"> <h1>Hi</h1> <h2>Hello</h2> </div> </body>
var h = $('#project').html(); $('#project').remove(); $(h).hide().appendTo('body'); alert("No error with whitespace nodes.");
Note: I know this is not a preferred way to duplicate elements on the page--this code is simply to demonstrate the problem. I discovered this problem when loading HTML fragment from the server and trying to insert them using $(html).hide().appendTo().
Change History (9)
Changed 7 years ago by brandon
comment:7 Changed 6 years ago by John Resig
- Resolution set to fixed
- Status changed from open to closed