Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



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

Posts: 217
Trades: 0
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?
__________________

Please login or register to view this content. Registration is FREE
Slick Nick is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-30-2006, 08:10 AM Re: Changing a tag from one element to another
Kirtan's Avatar
Who Am I?

Posts: 376
Name: Venkat Raj
Location: Salem, South India
Trades: 3
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, 05:26 PM Re: Changing a tag from one element to another
willcode4beer's Avatar
Super Moderator

Posts: 1,533
Name: Paul Davis
Location: San Francisco
Trades: 1
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, 01:24 AM Re: Changing a tag from one element to another
Extreme Talker

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


Thanks a ton! That helped me alot
__________________

Please login or register to view this content. Registration is FREE
Slick Nick is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Changing a tag from one element to another
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





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



Page generated in 0.13247 seconds with 12 queries