HTML, A href and name - html

Which one is the correct way or using a tag in this context?
<a name="test">Test</a>
or
<a name="test></a>Test

the correct is the first one
Test

The first example is correct
<a name="test">Test</a>

The correct syntax is link text
"name" is not a valid attribute for <a> tag. The allowed attributes are:
download, href, hreflang, media, ping , referrerpolicy, rel, target and type. Of course, <a> tag also allows global attributes and event attributes in addition to these.
If you want to use custom attributes consider using data- format like data-name
eg.
link text

Related

How to put a tag inside data-description

I have a'a' tag, something like this:
How can i put a link inside the data-description tag, so that i have a link inside a description link.
You can just write a tag there, e.g.
...
The value of an attribute is parsed as plain text, except for character/entity references, so the less than character < is just another data character.
Nothing inside a data-* attribute value is parsed as a tag, but that’s a special case of the fact that it is unspecified text. All use of such attributes is by definition dependent on what you do in your page or application. So if you need something to be interpreted as tags, just write the processing so that they will be so interpreted.
You cannot nest tags inside of tag attributes.
You can refer to this: Link inside a div link

a link with an <a> tag?

I need a link within an tag as follows:
<span><a data-description="TITLE - See more here" class="bullet" tabindex="-1"</a></span>
How can I have a link on the 'see more here' part?
Is this even possible?
Thanks
The "data-description" attribute is by definition, without any universal semantic meaning (any attribute beginning in "data-"). It might be used by some JavaScript library to add a tooltip, but the only built-in browser tooltip is the "title" attribute which your example is not using (and that does not support HTML, only text). You need to use some library like http://docs.jquery.com/Plugins/Tooltip

HTML attribute tag identifier?

If for example, I have a tag: Ex1, I want to identify what that tag is doing there. Title,class & id attributes aren't options as I use class&id for CSS and title displays text when hovered. So, is there any attribute to do that? Thanks!
Not really sure what your asking, but are you trying to apply meta-data as an attribute? If so, you can add more than one class (class="one two three fourClasses"), or use the data- attribute.
You can also use "data-[yourText]" as a cross-browser-safe attribute in any elements, and this often makes it nice to describe things because you can include more information in the custom data attribute value:
Ex1
Ex2
Ex3
What's wrong with <!-- HTML comments --> for annotations?

Jumping to anchors in JSP

When jumping to anchors on a JSP, HTML anchors do not work. Eg, something like
Link
...
<div id="name"></div>
fails because the server actually looks for a file named "filename.jps#name" and returns an error. Is there any workaround for this?
What you describe is called a fragment identifier and the target can be a named anchor or an identified element, for example
go to foo
<a name="foo">foo</a>
<div id="foo">foo</div>
with the named anchor variation demonstrated in this demo
Please also note that the HTML5 specification has deprecated the name attribute for a elements has been dropped, so an id would be the only HTML5 valid way to navigate to a fragment identifier.
I think that you've set a <base> tag in your document. All identifier links are also relative to it. If this is true, then you need to change your identifier links from
<a href="#name">
to
<a href="${pageContext.request.requestURI}#name">
See also:
Is it recommended to use the <base> html tag?

Use name in other element than div or span, but still possible to show img

<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?
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
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.
You could use the <a> tag with no href attribute.
As I said in response to your earlier question — use classes.
Basically, the only valid reason that I can think of where you would want to use the name attribute, is to have DOM access via document.getElementsByName()
or to use it as a FORM OUTPUT.
As a result, what you should be doing is using the HTML5 OUTPUT tag
and add the following in your HEAD tag for legacy browsers:
// Create a fake OUTPUT element, so IE can style it.
<script type="text/javascript> document.createElement("output");</script>
// Implement default style, so that it acts like a SPAN in other browsers:
<style type="text/css"> output { display:inline; border:0; outline:0; margin:0;padding:0; } </style>
http://html5doctor.com/the-output-element/
<output name="tumme"><img src="..." /></output>
If it is only for styling purposes or simple DOM query purposes
then you should use this as proposed earlier:
<span class="tumme"><img src="..." /></span>
or
<span id="tumme"><img src="..." /></span>
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 Link text.
Why do you need to use the name attribute? Why couldn't you simply use id instead?