Reply
Changing a tag from one element to another
Old 12-30-2006, 04:37 AM Changing a tag from one element to another
Extreme Talker

Posts: 217
I would like to know how I can use javascript to change a tag from one element to another. For instance, I might want to change a <a> tag with the id of "span" to a <span> tag. Any ideas on how to do this?
__________________
Helm Games
Slick Nick is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 12-30-2006, 09:10 AM Re: Changing a tag from one element to another
Kirtan's Avatar
Who Am I?

Posts: 377
Name: Venkat Raj
Location: Salem, South India
Although i am not able to get clear figure about your question, yet i think, you have to Rewrite whole html document with new tag using document.write()
__________________
All the Buddhas of all the ages have been telling you a very simple fact: Be -- don't try to become.
Kirtan is offline
Reply With Quote
View Public Profile Visit Kirtan's homepage!
 
Old 12-30-2006, 06:26 PM Re: Changing a tag from one element to another
willcode4beer's Avatar
Webmaster Talker

Posts: 696
Name: Paul Davis
Location: San Francisco
You can't actually change one to another (as far as I know) but, you could replace one with another.
Something like this might get you started:
Code:
function transformTag(tagId){
    var elem = document.getElementById(tagId);
    var children = elem.childNodes;
    var parent = elem.parentNode;
    var newNode = document.createElement("span");
    for(var i=0;i<children.length;i++){
        newNode.appendChild(children[i]);
    }
    parent.replaceChild(newNode,elem);
}
I tried to upload/attach a demo html page but the forum rejected the file type. I copied the demo file to my site in the meantime.
http://willcode4beer.com/tips.jsp?set=tagSwap
I'm not messing with the attributes here but, its the same idea as the children.
willcode4beer is offline
Reply With Quote
View Public Profile
 
Old 12-31-2006, 02:24 AM Re: Changing a tag from one element to another
Extreme Talker

Posts: 217
Ya replacing the tag is just fine. Basicly the same thing.


Thanks a ton! That helped me alot
__________________
Helm Games
Slick Nick is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Changing a tag from one element to another
 

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

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


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11901 seconds with 12 queries