Jump to content

jump to next/prev header <h1...6>


ferren

Recommended Posts

Jumping to next/prev page is commonplace. I didn't have much luck asking about jumping to next/prev id tags, but how about jumping to next/prev header? Currently, I write:

 

<h3 id="13">
<a class="up" href="#TOP">∧ </a>
<a class="up" href="#12">↑</a>
<a class="up" href="#14">↓</a>
Title of section</h3>
where I have to specify the next and previous id numbers.
For ease of maintenance, I'd like to be able to write something like
<h3 id="13">
<a class="up" href="#TOP">∧ </a>
<a class="up" href="#prev.hdr">↑</a>
<a class="up" href="#next.hdr">↓</a>
Title of section</h3>
making global changes simpler. I don't see a way to do this, but surely I am not the first person who wanted a way to increment an id automatically? 'current id ± 1' is the desired arithmetic, or 'last header' and 'next header'.
  • Like 1
Link to comment
Share on other sites

Yes but to do that, you HAVE to move beyond non dynamic html and into dynamic server script language such as php or javascript where you can manipulate html to achieve such results.Edit: It seems this has already been explained before for jumping between id, the same logic does not change because you are targeting header elements now, all html is just text in a format that a browser will interpret to produce a static web page.

Edited by dsonesuk
  • Like 1
Link to comment
Share on other sites

>Remember that IDs cannot begin with a numeric character.

 

Oops. I have ~1200 id tags that are entirely numeric, and they have been working smoothly for several years. If I don't change them, is this likely to get me in trouble in the future? Or is this a rule that browsers are content to ignore, like using width="33%" for sizing images--illegal but the only way to produce the desired effect as window width changes.

Link to comment
Share on other sites

It's not safe. It's not standard so browsers aren't forced to keep working that way.

 

You should always pass your HTML through the validator. http://validator.w3.org/

 

You shouldn't use the width attribute to make percentage widths, use CSS. http://www.w3schools.com/cssref/pr_dim_width.asp

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...