By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,623 Members | 1,892 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,623 IT Pros & Developers. It's quick & easy.

dynamic element access / moz Y - ie N

P: n/a
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
--
Jason Morehouse
Vendorama - Create your own online store
http://www.vendorama.com
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
--
Jason Morehouse
Vendorama - Create your own online store
http://www.vendorama.com


Works here. What was the error message?

Just fyi, 'item' is not the best choice for an identifier, as it's
already getting a serious workout as a method name, particularly in
MSIE.

If 'data' is purely textual (no markup) consider appending a text node
instead of using innerHTML.

Jul 23 '05 #2

P: n/a
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
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.