"Attribute name not allowed on element div at this point"
Asked Answered
R

5

35

I am getting a W3V validator error that I can't understand:

Line 31, Column 61: Attribute name not allowed on element div at this point.

That is this row:

<div name="message" class="jGrowl bottom-right errorGrowl"></div>

Full HTML:

<!DOCTYPE html>
<html>
    <head>
        <title>jGrowl</title>

        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>     
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>

        <script type="text/javascript" src="data/awo-jgrowl.js"></script>
        <script type="text/javascript" src="data/shortcut.js"></script>

        <link rel="stylesheet" type="text/css" href="data/awo-jgrowl.css">

        <script type="text/javascript">
            $(document).ready(function() {
                $('div[name=message]').awomsg('Input message', {sticky: true});
            });

            shortcut.add("m",function() {
                $('div[name=message]').awomsg('Input message', {sticky: true});
            });

            shortcut.add("h",function() {
                alert('ur doin it wrong');
            });
        </script>

    </head>
    <body>
        <div name="message" class="jGrowl bottom-right errorGrowl"></div>
    </body> 
</html>
Rabe answered 10/2, 2011 at 20:8 Comment(1)
Based on the answers below, the problem with this W3C error message is the expression "at this point." It doesn't make it clear if it means at the current point in time, at a particular place in the document, or at a particular place in the ordering of attribute elements. It's a bad error message. It would be better to leave of the "at this point" part: "Name attribute not allowed on element Div." It would have been a cleaner and easier to understand error message.Meadowsweet
S
23

The error message seems pretty self explanatory. You cannot have a name attribute on a div tag. So your code could look like this:

<div id="message" class="jGrowl bottom-right errorGrowl"></div>

and then use id selectors:

$('div#message')...
Siclari answered 10/2, 2011 at 20:10 Comment(0)
Z
29

I found some entry from:

Markup Validation Error: "Attribute name not allowed on element at this point" error #HTML5

Just in case you intend to define a custom attribute, you have to prepend the attribute with "data-".

So in this case, name would be: data-name="".

And you can reference it by 'div[data-name="value"]'.

Zohar answered 17/5, 2013 at 5:28 Comment(0)
S
23

The error message seems pretty self explanatory. You cannot have a name attribute on a div tag. So your code could look like this:

<div id="message" class="jGrowl bottom-right errorGrowl"></div>

and then use id selectors:

$('div#message')...
Siclari answered 10/2, 2011 at 20:10 Comment(0)
Y
19

There is no name attribute for div elements.

If you want to uniquely identify one, then use id.

If you want to mark one as a member of a group, then use class.

The only place you can use a name attribute (that hasn't been deprecated) is on form controls (input, select, textarea and button).

Yirinec answered 10/2, 2011 at 20:9 Comment(0)
A
9

This is a late response, but since this page just came up in a search:

Since the name attribute is not permitted on certain elements and has special significance in forms which you may not want, but any attribute name starting with "data-" is acceptable to use for purposes of your own, I recommend using the "data-name" attribute, like this:

<div data-name="message" class="jGrowl bottom-right errorGrowl"></div>

You can then write:

$('[data-name="message"]').text("Here is a new message!");

And otherwise manipulate the div via jQuery.

The use of data attributes has the virtue that it is unlikely to conflict with what your frontend designers may be doing with IDs and class names for CSS purposes.

In our office we have an understanding that IDs and classes are reserved for CSS, and JavaScript developers should leave them alone. Conversely, frontend designers are welcome to change the ID, classes or even element type of most things, provided that they don't mess with the data attributes.

Allaround answered 11/10, 2013 at 15:19 Comment(0)
C
1

The name attribute is not part of the specification for DIV elements. name is, generally speaking, only valid on form elements.

See: http://www.w3schools.com/tags/tag_div.asp

Culbertson answered 10/2, 2011 at 20:10 Comment(2)
With all due respect, sir, it is adequate for illustrating the matter at hand. Frankly, your sniping at my choice of links is far and away less useful than any site which may have some accuracy issues. I appreciate that you're trying to let everyone know, but I hardly think this is an appropriate venue for your crusade against a third-party site.Culbertson
While I agree that it is accurate in illustrating that particular point, the fact that w3schools is rife with mistakes on matters like this makes it suspect for any kind of reliable reference. He definitely could have been more diplomatic about it, though.Ichabod

© 2022 - 2024 — McMap. All rights reserved.