Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Is there a faster way to change span innerHTML

Reply
Thread Tools

Is there a faster way to change span innerHTML

 
 
Charlie T
Guest
Posts: n/a
 
      11-11-2004
Here is the code I am currently using.... can anyone think of a speeder process?

-------
function changeDiv(tagID, tagData) {
if(document.getElementsByTagName) {
var divs = document.getElementsByTagName('span');
for(var i = 0, n = divs.length; i < n; ++i) {
if(tagID == divs[i].id) {
divs[i].innerHTML = tagData;
}
}
}
}
-------
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      11-11-2004


Charlie T wrote:

> Here is the code I am currently using.... can anyone think of a speeder process?
>
> -------
> function changeDiv(tagID, tagData) {
> if(document.getElementsByTagName) {
> var divs = document.getElementsByTagName('span');
> for(var i = 0, n = divs.length; i < n; ++i) {
> if(tagID == divs[i].id) {
> divs[i].innerHTML = tagData;


Well if you have unique id values (as you should have) you can just access
document.getElementById(tagID).innerHTML = tagData

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Michael Winter
Guest
Posts: n/a
 
      11-11-2004
On Thu, 11 Nov 2004 18:57:58 +0100, Martin Honnen <(E-Mail Removed)>
wrote:

[snip]

>> function changeDiv(tagID, tagData) {
>> if(document.getElementsByTagName) {
>> var divs = document.getElementsByTagName('span');
>> for(var i = 0, n = divs.length; i < n; ++i) {
>> if(tagID == divs[i].id) {
>> divs[i].innerHTML = tagData;

>
> Well if you have unique id values (as you should have) you can just
> access
> document.getElementById(tagID).innerHTML = tagData


This is from a thread in September
(<URL:http://groups.google.com/groups?threadm=ee9445b6.0409071820.299b03d7%40post ing.google.com>).
The code above is based on my suggestion, but I was using classes, not ids.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I'm looking for html cleaner. Example : convert <h1><span><font>my title</font></span></h1> => <h1>my title</h1>… Stéphane Klein Python 2 03-30-2010 12:35 AM
Re: I'm looking for html cleaner. Example : convert <h1><span><font>my title</font></span></h1> => <h1>my title</h1>… Stefan Behnel Python 0 03-29-2010 08:14 PM
Can span include span? Fulio Open HTML 5 06-26-2009 10:24 PM
xhtml, innerHtml, appendChild, and innerHTML. what is the exact proper way to do this with DOM sonic Javascript 5 07-11-2006 08:17 AM
DataGrid (body only) contained in <span>...</span> tags Dan Bishop ASP .Net Datagrid Control 2 06-07-2004 04:00 PM



Advertisments