views:

217

answers:

4

Hi,

Please tell me, Can I rely completely upon jquery html() method that it'll perform like innerHTML? is there any difference between innerHTML and jquery html() method? and if these both do the same work can I used jquery html() method in place of innerHTML?

My problem is: I am working on already designed pages, the pages contains tables and in javascript the innerHTML property is being used to populate them dynamically, application is working fine on ff but IE fires error "unknown runtime exception". I used jquery html() method and IE error has stopped. but I'm not sure it will work for all browsers and I'm not sure to replace all innerHTML properties to jquery html() method. pls suggest

Thanks a lot

+1  A: 

"This method uses the browser's innerHTML property." - jQuery API

http://api.jquery.com/html/

codersarepeople
+3  A: 

To answer your question:

.html() will just call .innerHTML after doing some checks for nodeType's & stuff. It also uses a try/catch block where it trys to use innerHTML first and if that fails, it'll fallback gracefully to jQuerys .empty() + append()

jAndy
+2  A: 

If you're wondering about functionality, then jQuery's html() performs the same intended functionality as innerHTML, but it also performs checks for cross-browser compatibility.

For this reason, always use jQuery's html() instead of innerHTML where possible.

box9
+1  A: 

innerHTML is not standard and may not work in some browsers. I have used html() in all browsers with no problem.

Craig