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

Javascript code removing anchor tags

P: 5
HI ,

i have a code :

<a href="#" >Hyperlink</a>

Now how do i remove the anchor tag dynamically using Javascript?
Mar 3 '09 #1
Share this Question
Share on Google+
5 Replies

Expert Mod 15k+
P: 16,027
Find the link in the DOM (document.getElementsByTagName() or getElementById() if it has an ID) and then use removeChild:
Expand|Select|Wrap|Line Numbers
  1. document.body.removeChild(..)
Mar 3 '09 #2

P: 5
Thanks for the reply....but could you plz give a more detailed description of the code .
Mar 3 '09 #3

Expert Mod 5K+
P: 8,639
explaind by MDC: removeChild() - MDC
Mar 3 '09 #4

Expert Mod 15k+
P: 16,027
If you don't know the parent node, you can use the parentNode property:
Expand|Select|Wrap|Line Numbers
  1. node.parentNode.removeChild(node);
where node is the element to be removed.
Mar 4 '09 #5

P: 1
As people say, this will do it:
Expand|Select|Wrap|Line Numbers
  1. $(document).ready(function() {
  2.  var a=document.getElementsByTagName('a');
  3.  for(var i=0;i<a.length;i++)
  4.   if ((a[i].attributes['href'] && a[i].attributes['href'].value=='#') && (a[i].innerHTML=='Hyperlink'))
  5.    a[i].parentNode.removeChild(a[i]);
  6. });
Aug 5 '11 #6

Post your reply

Sign in to post your reply or Sign up for a free account.