...

View Full Version : name link issues



tokio
02-21-2009, 01:29 AM
Im trying to code a name link so that when an idnivdual click on the link, they will be sent to an area of my site with the specific code. Here is the code that i have:

<a href="#D5"> Go to chapter two </a>
<p> happy </p>

<a name="D5"> chapter two </a>

Any hints? Thanks.

optimus203
02-21-2009, 01:49 AM
If your trying to call the anchor that is on a different page from your source, you should use: <a href="page.html#d5">Chapter Two</a>

If our calling from within the same page, you do not need to have content in our anchor name, just the name itself (unless of course you want to print out content): <a name="chapter2"></a>

abduraooft
02-21-2009, 08:41 AM
NO! Never use the name attribute for the element(deprecated) to make such kind of anchor. Instead use the id attribute, so that you can target any element inside a document, like


<h2 id="heading2"></h2>


<!-- will jump to the element with ID 'here' -->
<a href="#heading2>link</a>

tokio
02-21-2009, 05:58 PM
NO! Never use the name attribute for the element(deprecated) to make such kind of anchor. Instead use the id attribute, so that you can target any element inside a document, like


<h2 id="heading2"></h2>


<!-- will jump to the element with ID 'here' -->
<a href="#heading2>link</a>

I dont get this example. I fixed the error in your code which was simple but you forgot to quote the attribute around heading2. However, by having a link that says link, how is this taking the indivdual to an designated spot on the page?

Apostropartheid
02-21-2009, 06:36 PM
It's the fragment identifier which is the key. A link targeted at somewhere ending in a hash and a string (e.g. #cptr2) will tell the browser to search for an element with the ID of the fragment (e.g. <element id="cptr2"/>) and jump the viewport to that location. The name attribute used to be used instead of IDs, but this is now a deprecated practice.

tokio
02-21-2009, 11:15 PM
Sorry i learn best by examples, mind giving an working example that uses "id," thanks.

Apostropartheid
02-22-2009, 12:45 AM
<?xml version="1.0" charset="utf-8"?>
<!doctype html>
<html xml:lang="en">
<head>
<title>Cats</title>
<meta http-equiv="Content-Type"
content="application/xhtml+xml; charset=utf-8"/>
</head>
<body>
<h1>Articles on cats</h1>
<ul>
<li><a href="#noises">Noises</a></li>
<li><a href="#appearance">Appearance</a></li>
</ul>
<h2 id="noises">Noises</h2>
<p>Cats (colloq. &ldquo;kitties&rdquo;) make a sound which is spelt in different manners depending on region and preference. Most prevailant are the spellings <b>miaow</b> and <b>meow</b>. I like the first version. miaow!</p>
<h2 id="appearance">
<p>Cats are very small animals. They have tails&hellip;</p>
</body>
</html>

That should show the behavior.

Rowsdower!
02-22-2009, 01:11 AM
...However, by having a link that says link, how is this taking the indivdual to an designated spot on the page?

Hello and welcome to the forums. I just want to clarify that it doesn't matter what you type here:
<a href="#heading2">link</a>

To illustrate, all of these links would have the same exact effect:
<a href="#heading2">link</a>
<a href="#heading2">potato</a>
<a href="#heading2">I like coffee</a>
<a href="#heading2">where's the beef?</a>
<a href="#heading2">this is not a link, it leads NOWHERE!</a>

The functional portion of the code is this segment:
<a href="#heading2">link</a>

optimus203
02-22-2009, 04:09 AM
NO! Never use the name attribute for the element(deprecated) to make such kind of anchor.

Of course. Sorry, I'm a little sleep deprived...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum