Posts: 23
Threads: 7
Joined: Jan 2015
I could use some help figuring out why my anchor tags are not working. I want to link to a specific line of text on another page on the site using the following markup:
<div class="team"><a href="staff#jacquie">Jacquie Wyant</a></div>
<a name="jacquie">Jacquie Wyant</a>
Any help would be greatly appreciated!
See attachments for details.
Posts: 6,267
Threads: 182
Joined: Sep 2011
Posts: 1,928
Threads: 88
Joined: Apr 2010
<div class="team"><a href="/staff#jacquie">Jacquie Wyant</a></div>
Posts: 6,267
Threads: 182
Joined: Sep 2011
No
<a id="jacquie">Jacquie Wyant</a>
<h1 id="jacquie">Jacquie Wyant</a>
Posts: 305
Threads: 15
Joined: Mar 2014
2015-05-28, 07:11:17
(This post was last modified: 2015-05-28, 07:20:59 by Tyblitz.)
That should be fine, according to browser tests I did a while ago:
Quote:Apparently Mozilla Firefox doesn't associate the id attribute with a location in the HTML Document for elements other than <a>
but uses the name attribute instead, and Google Chrome does exactly the opposite. The most cross-browser proof solution would be to either:
1.Give your anchor divs both a name and an id to ensure max. browser compatibility, like:
<a href="#map">Go to Map</a> <!-- Link -->
----
<div id="map" name="map"></div> <!-- actual anchor -->
Demo: http://jsbin.com/feqeh/3/edit
2.Only use <a> tags with the name attribute as anchors.
In this case, if Jacquie is a location on the same page the href attribute should be #jacquie and if it's on another page called staff it should be staff#jacquie, and should work regardless whether you're using a named anchor or id'd element.
If you're using ID's and want to be absolutely sure it works you can always put this type of script at the bottom of the linked page:
Code:
<script>
var loc = location.href;
if (loc.match('#')) && document.getElementById(loc.split('#')[1]))
document.getElementById(loc.split('#')[1]).scrollIntoView();
</script>
Posts: 1,928
Threads: 88
Joined: Apr 2010
2015-05-28, 16:56:52
(This post was last modified: 2015-05-28, 17:04:06 by Oleg06.)
on my site all the anchor work and name and id
http://gs-blog.business-website.ru/yakorya/
maybe he uses the plugin Custom menu
Posts: 23
Threads: 7
Joined: Jan 2015
Thanks for all the input from everyone, however I tried both id and name and neither works. It goes to the proper page but doesn't find the tagged div. Any ideas?
Posts: 6,267
Threads: 182
Joined: Sep 2011
what browser? works for me
Posts: 23
Threads: 7
Joined: Jan 2015
I've viewed it in Safari, Chrome and Firefox so far. Like I said, the link goes to the staff page but it doesn't take you to the tagged div on the page. Go to www.challengeyourbody.com and on the "About Us" page, click on Kevin Needler's name. It should go to his bio on the page, but doesn't.
Thanks for looking.
Posts: 6,267
Threads: 182
Joined: Sep 2011
your link anchor has quotes around it
Posts: 305
Threads: 15
Joined: Mar 2014
(2015-05-29, 04:55:27)shawn_a Wrote: your link anchor has quotes around it
Lol yeah the referring link is
http://www.challengeyourbody.com/about-us/"staff#kevin”.
Should be
http://www.challengeyourbody.com/staff#kevin
Posts: 1,928
Threads: 88
Joined: Apr 2010
Code:
<a href=“staff#kevin”>Kevin Needler</a>
replace it
Code:
<a href="staff#kevin">Kevin Needler</a>
Posts: 23
Threads: 7
Joined: Jan 2015
Well, thanks everyone. It's the small things that trip me up! LOL!