...

View Full Version : Correct xhtml strict tag for a link.



Jerome
01-02-2004, 12:52 PM
Hi,

When I have a sentence in a paragraph like

<p>HAPPY 2004 TO ALL OFF YOU</p>

and I like to add an onclick event to the word 2004 as well as a hover event with css, which is the correct tag to use?

<a>
<span>
<else>

Thanks for Your time,
Jerome

me'
01-02-2004, 01:01 PM
It depends on: If you want IE compliancy, use <a>, as it's the only tag IE supports :hover on.
What are you going to do with the onclick event? That'll really tell which tag you should use.

Jerome
01-02-2004, 01:11 PM
IE only supports hover on <a> ? hmm !

I want to get rid off a declaration like:

<a href="javascript:function();">2004</a>

xhtml strict, for a commercial (thus IE supporting) site

Jerome

oracleguy
01-02-2004, 06:47 PM
This would be the way to do it:

<a href="Alternate.htm" onclick="javascript:function();" title="The title of the link">2004</a>

Unless I am forgetting something...

me'
01-02-2004, 07:47 PM
Originally posted by oracleguy
This would be the way to do it:

<a href="Alternate.htm" onclick="javascript:function();" title="The title of the link">2004</a>

Unless I am forgetting something... Yep. onclick="function()", no protocol needed there. Also, if you don't want to change the page, href="#".

brothercake
01-02-2004, 07:50 PM
You're right about the protocol not being necessary for onclick (although it doesn't matter if it is there), but you're wrong about the use of "#" for the href - you should never do that - always make the href go somewhere and then return false on the onclick handler, otherwise you'll create a link that for non-javascript browsers does nothing at all.

jkd
01-02-2004, 11:22 PM
Originally posted by brothercake
You're right about the protocol not being necessary for onclick (although it doesn't matter if it is there), but you're wrong about the use of "#" for the href - you should never do that - always make the href go somewhere and then return false on the onclick handler, otherwise you'll create a link that for non-javascript browsers does nothing at all.

Well, onclick="javascript:bla()" actually isn't specifying any protocol. I'm probably going to end up biting my tongue since I haven't tested this, but I believe what is going on is that you are labeling the codeblock "bla()" with the label "javascript". Check the specs for labelled statements.

me'
01-03-2004, 11:50 AM
Originally posted by brothercake
You're right about the protocol not being necessary for onclick (although it doesn't matter if it is there), but you're wrong about the use of "#" for the href - you should never do that - always make the href go somewhere and then return false on the onclick handler, otherwise you'll create a link that for non-javascript browsers does nothing at all. Good point. Maybe you could do some detection to be really friendly:
<script type="text/javascript">
//<![CDATA[
document.getElementById('message').getElementsByTagName('a')[0].addAttribute('onclick', 'function() {alert(\\'hello world\\')}');

//]]>
</script>
<h2 id="message">HAPPY <a>2004</a> TO ALL OF YOU!</h2>

brothercake
01-03-2004, 11:57 AM
Originally posted by me'
//<![CDATA[

//]]>
What is it with this putting script in commented CDATA braces? If it's an HTML document surely it shouldn't have CDATA sections, and if it's an XML document then surely the commenting-out is not necessary?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum