Jason Morehouse wrote:
Hello,
I want to access an element by passing part of the name to the function...
eg:
function show_files(item,data) {
document.getElementById('row-' + item).innerHTML = data;
}
show_files('2','hello world');
This seems to work fine in Firefox, but errors in IE. What is the best
way to dynamically access an element?
Cheers
-J
It depends a bit on what "row-2" is. If it's a reference to a table
row, don't attempt to modify it using innerHTML:
"...you also cannot set InnerHtml on TABLE and TR elements, as
assigning malformed HTML to these elements could corrupt the
rendering of the document. Use AppendChild or the insertRow and
insertCell methods on the unmanaged IHTMLTable interface to add rows
and cells to a TABLE".
<URL:http://longhorn.msdn.microsoft.com/lhsdk/ref/ns/system.windows.forms/c/htmlelement/p/innerhtml.aspx>
Please take the advice on this page with a grain of salt, its suggested
use of innerText should be avoided unless you like IE-only code,
similarly for InsertAdjacentElement. Also note the erroneous use of
"innerHtml" rather than "innerHTML" - and they invented it!
innerHTML can be used to change the content of a cell or other element,
but not other parts of a table - though you can use it to change/create
an entire table, from <table ... to ...</table>.
--
Rob