473,651 Members | 3,012 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript code removing anchor tags

5 New Member
HI ,

i have a code :

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


Now how do i remove the anchor tag dynamically using Javascript?
Mar 3 '09 #1
5 10582
acoder
16,027 Recognized Expert Moderator MVP
Find the link in the DOM (document.getEl ementsByTagName () or getElementById( ) if it has an ID) and then use removeChild:
Expand|Select|Wrap|Line Numbers
  1. document.body.removeChild(..)
Mar 3 '09 #2
smita232
5 New Member
Thanks for the reply....but could you plz give a more detailed description of the code .
Mar 3 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
explaind by MDC: removeChild() - MDC
Mar 3 '09 #4
acoder
16,027 Recognized Expert Moderator MVP
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
Stano Kobella
1 New Member
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. });
  7.  
Aug 5 '11 #6

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

Similar topics

3
7971
by: dan glenn | last post by:
hi. I want to code a 'preview' function into a guestbook entry page. I can do it with a button that posts, bringing up a whole new page showing a preview of what has been entered, and then the user could hit a 'return to entry form' button or some-such and go back to the form. But what I want to do instead is just use an HTML link with some javascript to grab the form's textarea value, and open another browser window that uses a php file...
0
1381
by: David Pratt | last post by:
Hi. I am putting together a database application on Zope. I have built a pager for my records (20 per page) but do not want the browser scroll bars to reset to the top of the browser each time the pager is advanced to the previous or next page. The normal behavior is fine for everything but the anchor tags I am using for the pager. Instead of resetting when a new page is sellected, I want the vertical scrollbar to maintain its ...
4
6301
by: Sergio del Amo | last post by:
i, I have the next html page <html> <head> <script> <!-- function insertcode() { var code ="<p> blablabal babala babababab</p><h1>here comes header</h1><span>fadfafa<a href=\"fadfaf\">anchor</a>blalbababa</span>"
9
2109
by: Astra | last post by:
Hi everybody Wonder if you could help me out. I created a simple JavaScript routine to enable a user to click backwards and forwards between small news articles. This routine works fine in IE and Safari, but in the latest FireFox I get no title or article, but do see the prev and next links and the article number. My HTML and JS simple routine is as follows:
5
25845
by: elsenraat_76 | last post by:
Hello! I was wondering if someone could help me out with a problem I'm having? I'm trying to input a javascript value into an anchor tag (from a function), but don't have an event to call the function...if that makes sense. Here's what I mean... I have a javascript array set up like so: <script language="javascript" TYPE="text/JavaScript"> //custom object constructor
11
12587
by: yawnmoth | last post by:
If using an onclick event handler to execute javascript when an anchor element is clicked on, what should the href attribute be? #? javascript:void(0)? Something else?
5
2334
by: acord | last post by:
Hi, I m getting annoying display problem when placing javascript tags in a html page. Should the javasscript tags placed at the beginning of a html page before anything start? or placed between the <head></head> tags? If I placed the script tags at the beginning of the html page, I can have the Draggale Layer shown and movable by the mouse, but the entired page will not read the style.css file (as I found the font displayed very ugly);...
24
6320
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to have on his site, a Javascript Calculator for working out the cost of what they want, for example: 1 widget and 2 widglets = £5.00
12
9161
by: wavedancer | last post by:
I just tried validating the page I'm working on as <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> and it fails on the PayPal form: <form target="paypal"... /> there is no attribute "target" <input type="hidden" name="cmd" value="_cart" /> document type does not allow element "input" here; missing one of "p", "h1", "h2", "h3", "h4", "h5", "h6", "div", "pre",...
0
8361
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8807
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8466
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8584
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7299
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5615
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1912
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.