0

I saw this on a question recently.

<input type="radio" mess="whats up" name="q1" value="A" class="correct"/>

I can't get what the mess attribute do, and I couldn't see any result on the internet. So what is the mess attribute for?

Community
  • 1
  • 1
  • 2
    There is no such attribute. – SLaks Jan 05 '14 at 19:35
  • @SLaks you can see the question, I provided the link. –  Jan 05 '14 at 19:36
  • That question you linked to actually answers this - it's not a standard attribute, it's an approach the poster used to attach custom data to DOM elements. – DCoder Jan 05 '14 at 19:36
  • @DCoder so is it possible to add any attribute you want to an html element? –  Jan 05 '14 at 19:37
  • 1
    [You can add custom attributes to your HTML, but unless you're using html5 and specifically allowed attribute names, it will make your document invalid](http://stackoverflow.com/a/1735268/1233508). – DCoder Jan 05 '14 at 19:43

3 Answers3

4

It can be called as custom attributes intended to store a piece of information (purely for developer puropse)but it not advisable.

Instead you can go for HTML5 custom data attribute like

data-mess="whats up"

It can be easily accessed with .data() in jQuery.

<input type="radio" data-mess="whats up" name="q1" value="A" class="correct"/>

See

$('.correct').data('mess') // to getch the value
$('.correct').data('mess', 'some value')  //to update the value

FYI:*custom data-** is purely validated with w3c validator. Whereas not with yours.

Community
  • 1
  • 1
Praveen
  • 55,303
  • 33
  • 133
  • 164
1

It's just a way to store arbitrary data in the tag. It does whatever the programmer intends it to do. Some people prefer to add custom attributes via data-foo, others prefer this syntax.

Mohamad
  • 34,731
  • 32
  • 140
  • 219
1

There is no mess attribute, in the question he just used it to attr and get the value through JQuery.

For example:

checked = $('input:checked').attr('mess'); sets checked to whatever the checked input had on the 'mess attribute', as seen in the question.

Another example:

$('#BobDiv').attr('txt'); will return 'Bob' if your HTML is <div id = 'BobDiv' txt = 'Bob' />

As seen here, you have to amend it in your !DOCTYPE declaration, though.

Community
  • 1
  • 1
Cilan
  • 13,101
  • 3
  • 34
  • 51
  • So can I add any attribute I want to do so? –  Jan 05 '14 at 19:39
  • @user689 Yes, basically, but you have to amend your !DOCTYPE declaration (i.e. DTD) to allow it – Cilan Jan 05 '14 at 19:40
  • just for your information however still this will suffer error in w3c html5 validator `Attribute mess not allowed on element input at this point.`. – Praveen Jan 05 '14 at 20:07
  • 1
    @PraveenJeganathan Yes, I agree, that's why there are better ways to do stuff like this – Cilan Jan 05 '14 at 20:09