/    Sign up×
Community /Pin to ProfileBookmark

Using an id as an anchor name

Hi,

The usual way to create an anchor is with the a element, but I read you can use the id name of any other element to create an anchor. I’m using the h2 id name as an anchor. This seems to work fine in IE6 but will not work in Firefox. Anyone know anything about this?

thanks

to post a comment
CSS

4 Comments(s)

Copy linkTweet thisAlerts:
@WebJoelJan 19.2008 — Do you mean like id="body" and class="html"? -Sounds untenable to me. Aren't certain 'words' considered to be "reserved words" and expected only for naming elements? Maybe not, you could have a class="p" and not have it mean "<p>" as it's the delimiters "<" and ">" (and " />") that make it a [U]tag[/U].. but when you begin having problems making this work, do tell. ?

Elements, and their 'id' and their 'class', really should be named [U]semantically[/U], -call them what they ARE or what they DO. -Save yourself from the mania of a convoluted and overly-complicated layout.

I can see it now... code" <div id="a26449-ad3" class="b-129964 c-a29984-24 dd-a123-6658"> followed with request: "it works in IE but not Firefox"... :mad:

Well maybe it [I]should[/I] work but who is going to want to explore this and fix it? :rolleyes: (whistling to self and walking towards door...) Or am I misunderstanding the question entirely? ?
Copy linkTweet thisAlerts:
@Major_PayneJan 19.2008 — See [B]Links[/B] and [B]Syntax of anchor names[/B].

Ron
Copy linkTweet thisAlerts:
@johnnyblotterauthorJan 21.2008 — You're misunderstanding. For example:

<a name="bob" href="#">link</a>

There's the anchor. And to jump to that anchor:

<a href="#bob">Go to Bob's part of the page!</a>

BUT...I'm trying to do it like this...

<h2 id="bob">Bob</h2>

<a href="#bob">Go to Bob's part of the page!</a>

Like I said, not the typical way of doing it, but here it is in my Elizabether Castro book...says you can use id names of elements as anchors. This works in IE6 but not firefox.

Sorry I wasn't clearer about the issue. What I ended up doing, because the h2 element was in the right spot for the anchor, was this...

<a name="bob></a><h2>Heading</h2>

<a href="#bob">Go see Bob</a>

Not the best semantically, but the best solution I could come up with.
Copy linkTweet thisAlerts:
@Major_PayneJan 21.2008 — Don't think anyone said you couldn't use "id" or "name" for anchor names. That's brought out in the links posted. Second link just shows you right/wrong ways of using either.

Ron
×

Success!

Help @johnnyblotter spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...