newwebdesigner2 — 2013-04-24T02:42:16-04:00 — #1
On page 278 of "PHP and MySQL: Novice to Ninja"
<a href="?">Continue shopping</a>
What does the ? do in the href attribute?
avram — 2013-04-24T03:12:22-04:00 — #2
Leaving href empty would link to the same page the link is located on. So if on index.php, <a href="">test</a> will link to index.php. With "?" set as a href attribute, it'll link to index.php? - having no (useful) effect at all, except maybe reloading page
starlion — 2013-04-26T09:00:23-04:00 — #3
Just wait until HTML 5, when the href is entirely optional
Avram is correct in that it links you to the page you are currently on. However there IS a difference between "" and "?". Linking with "" will reload the current URL with the same GET variables attached. Linking with "?" will remove all GET (query-string) variables from the URL.
So if you're on index.php?members=me, and click a link with href="", you'll go to "index.php?members=me". If you click on a link with href="?", you'll go to "index.php?"
antnee — 2013-04-26T11:59:40-04:00 — #4
Isn't it already optional? If you're defining an anchor, rather than a link? ie <a name="news">News</a>
I presume you're saying that you would be able to do simply <a>News</a> or <a id="news">News</a> and do something with JS instead?
starlion — 2013-04-26T13:35:48-04:00 — #5
Unless I am misreading the HTML 5 document i'm looking at, any <a> that has content without an href attribute would be treated as if it had href="".
antnee — 2013-04-26T13:42:15-04:00 — #6
If the a element has no href attribute, then the element represents a placeholder for where a link might otherwise have been placed, if it had been relevant, consisting of just the element's contents.
Right near the top. Haven't read the whole thing, but using <a name="foo"> is the traditional way to link to a part of the page. I believe it may be deprecated in favour of linking directly to an id on a non-anchor element
starlion — 2013-04-26T13:46:54-04:00 — #7
Correction. <a name="foo" /> is the traditional way. A content-less tag.
antnee — 2013-04-26T13:49:50-04:00 — #8
A) I didn't mean content-less, I just didn't enter the content or closing tag, so it would be <a name="foo">Foo</a>
B) Yours is XHTML, which IMHO should never be used unless you need to parse the content with an XML parser anyway
newwebdesigner2 — 2013-04-26T13:51:29-04:00 — #9
avram and starlion,
those explanations make sense in light of the examples i was looking at.
felgall — 2013-04-27T18:00:14-04:00 — #10
It is perfectly reasonable to use XHTML as long as you don't need to support IE8. That's why all that XHTML5 development work with all the new tags is currently underway.
Once IE8 is dead HTML will become unnecessary as all browsers will then support the far superior XHTML5 variant.
newwebdesigner2 — 2013-04-29T05:37:47-04:00 — #11
wait what? IE 8 doesn't use xhtml? so what should I use? just regular html in the meantime? how prevalent is ie 8?
antnee — 2013-08-14T07:28:50-04:00 — #12
Sorry @NewWebDesigner2, didn't see your reply until months later.
XHTML is considered malformed HTML by most browsers unless you also use the correct MIME type, ie application/xhtml+xml. But if you used that in early IE versions you would see an XML DOM, and not a rendered web page. So if you were sending XHTML code, the browser was treating it as HTML anyway. There's no harm in using XHTML, and it's important to use it if you need to process it using an XML parser of some kind (don't forget that XML is strict, compared to HTML), but it wouldn't validate correctly.
See here for more information: http://www.w3.org/TR/xhtml-media-types/#media-types
You'll see that there are acceptable usages of XHTML and text/html (the default for most webservers) but I suspect that they won't cover most of your use cases.
Lots of people think they've been using XHTML for years, but they haven't been doing it properly, frankly.