tags:

views:

142

answers:

5
<span name="tumme"><img ...

is not valid because "name" is not valid in "span".

But I need to use name="tumme" and I need to be able to use text and img inside the tag.

So what tag can I use together with "name" and on the same time follow w3c?

+1  A: 

You could use the <a> tag with no href attribute.

Time Machine
But is it possible/w3c-ok to show img inside a a-tag?
Johan
yes, it is possible but please tell us why you need to do this.
Oliver Giesen
Given the context of the OP's earlier questions, this would be a hack. The use is the name attribute is for scripting not linking. A class is the right way to go here.
David Dorward
A: 

name is only valid in the <a> tag IIRC (and form elements as was pointed out by David in the comments) but I'm pretty sure that is not what you're after:

<a name="whatever"></a> would create an "anchor" on a page that could be linked to with <a href="#whatever">Link text</a>.

Why do you need to use the name attribute? Why couldn't you simply use id instead?

Oliver Giesen
There are plenty of elements that allow the name attribute (every form control for instance). The a element is one of the few which have seen official support removed (albeit in XHTML 1.1)
David Dorward
it has? so, how do you create an anchor in XHTML then?
Oliver Giesen
I try that occasionally but found that browser support for that concept is still flaky - it's probably been half a year or so since I last tried linking to an `id` though...
Oliver Giesen
Since HTML 4.0 the preferred way to create a point that can be linked to in a document is to set an id attribute on any element (such as a div surrounding the section you are linking to, or a heading at the start of it)
David Dorward
The last major browser that had issues linking to ids was Netscape 4
David Dorward
oh boy, looks like I need some more caffeine... I just found a section in our own code where I *did* link to `id`s just a couple of weeks ago... <blush/>
Oliver Giesen
...still wasn't aware that `<a name=` was deprecated. thanks for the hint.
Oliver Giesen
+1  A: 
David Dorward
a lot of code though
Johan
using classes is hard, lets go shopping!
jfar
this is very probably the correct answer when you know what the question really should have been but without knowing about the context of the question (i.e. the previous questions by this poster) this answer has no significance... :-P
Oliver Giesen
A lot of code? It is one call to a pre-written function, and a loop over its results.
David Dorward
@Oliver - Well, since I LINKED to that question (or rather, my answer to that question) I think the significance is easy enough to find.
David Dorward
fair enough. it's still not an answer to the question that was actually asked...
Oliver Giesen
The joy of the X-Y problem (comment added to question)
David Dorward
+2  A: 

Is there a reason you must use a "name" attribute rather than a class or an id? Since both class and id are valid for span elements, and since span appears to be the most appropriate element to use,I'd set one of those to "tumme" rather than bending another element into shape.

dnagirl
http://stackoverflow.com/questions/1159361/update-two-same-value-in-html-with-one-ajax-response is the reason
Johan
please add that information to your question - so I could properly upvote David's answer... ;)
Oliver Giesen
You still don't need to use a "name" attribute. Give each span a unique id so you can tell them apart if you want to, and give each span the class "tumme" so you can affect their behaviour as you wish. Use the javascript suggested in the other thread to pull all the elements with class="tumme", or use the id to pull the element and then check if it's class="tumme"
dnagirl
+2  A: 

To answer the question directly, as per the spec the name attribute is allowed on the following HTML elements (very few of these will be useful to you):

  • BUTTON
  • TEXTAREA
  • SELECT
  • FORM
  • FRAME
  • IFRAME
  • IMG
  • A
  • INPUT
  • OBJECT
  • MAP
  • PARAM
  • META
DisgruntledGoat