Thanks for the explanation, Rob. I'll have to check into setAttribute...am I correct in assuming that "setAttribute" is a Javascript function, but not jQuery?
Also, your statement, "There is no 'HTML in the DOM'. HTML is used to create a DOM." seems like semantics. So is it correct to say that a DOM contains no HTML? Rick -----Original Message----- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of RobG Sent: Wednesday, September 02, 2009 11:05 PM To: jQuery (English) Subject: [jQuery] Re: Is this "quirk" of jQuery still true? On Sep 3, 6:55 am, "Rick Faircloth" <r...@whitestonemedia.com> wrote: > I read that in an article dated October 17, 2008, that it was not possible > to change the actual > > HTML in the DOM There is no "HTML in the DOM". HTML is used to create a DOM. > of the "value" attribute of a text input using > $(this).val('myNewValue'); Because that changes the DOM value property, not the HTML value attribute. The HTML value attribute (if present) is used to set the DOM defaultValue property and provide an initial value for the value property. User initiated changes to the input's value will change the DOM value property. Setting the value property will change the displayed value. If the input is in a form and the form is submitted, the value of the value property is submitted (assuming the input is successful). The defaultValue is used to set the value of the input if the form's reset method is called and can be changed by assigning a new value to it programmatically. The HTML attribute value can be changed using setAttribute. There is no specification for how to generate HTML from a DOM, what you'll get is dependent on the browser and the method or tool (e.g. the browser-dependent innerHTML property[1]) Using innerHTML as the tool to convert DOM to HTML, it can be seen that in IE changes to the element's value property are reflected in the value attribute but not in Firefox. Other tools may have different results. If you want consistent behaviour in that regard, do the DOM to HTML transformation yourself. > My experiments just now bear this out. > > Is this still true? The writer of the article developed a work-around using > a hidden input and > > manipulating its value with a rel to the original input. Is this still the > best way? If you want to reliably set the HTML attribute value, use setAttribute as it is specified as doing that (and realise that setAttribute is broken in IE in places). 1. innerHTML is a widely copied IE proprietary property that has no public specification and is known to be implemented differently in different browsers. -- Rob