You need to use document.getElementsByTagName('a') to get a collection of all the 'a' nodes in the DOM. Then you would iterate through each one... querying it's childNode for the 'text' node that contains the text you want to keep ("webpage" in your example above). Then you would clone that 'text' node, remove the 'a' node and add in the 'text' node you cloned.
Repeat until you have finished iterating the collection.
Some very well written posts in this forum discuss how you can do pretty much everything I have described above.
However, it is the part where I will query, clone, remove and add where I can't get it to work in both IE and Mozilla. Do you by any chance have any tips on a working solution in both browsers?
The simplest approach is to dis-function the href hyperlink. If there is only one hyperlink to xxx.html, it can be done this way.
[tt]
function handler() {
var canchor=document.getElementsByTagName("a");
for (var i=0;i<canchor.length;i++) {
if (canchor.href.indexOf("xxx.html")!=-1) {
canchor.href="javascript:void(0)";
}
}
}
[/tt]
But in you case the link still remains and the text is underlined, right? I want it to be transformed from a link to ordinary text both in IE and Mozilla.
>I want it to be transformed from a link to ordinary text both in IE and Mozilla.
I can give you a quick solution for ie.
[tt] canchor.outerHTML=canchor.innerHTML;[/tt]
tsuji - he wants to remove the <a href> and the </a> part completely.
pichdude - do some searching on this forum using key words from the post I made... you will find plenty of examples of this kind of thing. You can solve the problem yourself if you take it in small chunks. The process I outlined is totally cross-browser and cross-platform. You just need to research the syntax.
Thanks Jeff, I appreciate the interpretation. I gave one "simplest" thing to do. If the op is not completely happy with the reduced performance, it is fair enough.
The second .outerHTML=.innerHTML is another solution for ie only, as I said.
Here is now the cross-browser solution also taking always the simplest path.
[tt]
canchor.removeAttribute("href");
[/tt]
That make no difference in display with what required.
The last solution is effective only on ff/nn. By combining both, the functional solution is this.
[tt]
if (document.all) { //simplistic ie identifier
canchor.outerHTML=canchor.innerHTML;
} else {
canchor.removeAttribute("href");
}
[/tt]
- tsuji
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.