-1

I am working on HTML and JavaScript. I need to store some values in HTML and use that some for other purpose for other languages like JAVA (HTML parsing).

Can I use own attributes like column='helloworld'? Is it valid in HTML?

I also see "data-", but I don't know what happened if I do not use "data-".

Does that give any error ?

Please elaborate someone, I have no expertise in HTML.

<input type="text" id="1" class="text-clone" name="default">
<select id="Name" class="dropdown-clone" name="Name">
  <option value="">Name</option>
  <option value="MyName">myName</option>
</select>

$('#'+id).find("input[type=text]").attr("column",$("#Name").val());

Name value is any string like "myName".

after this when I see on my browser by using inspect element , column="myName" . So I am confused why we can not do this which I did , that is wrong or correct . safe or not ?

mplungjan
  • 169,008
  • 28
  • 173
  • 236
s.singh
  • 23
  • 5

1 Answers1

0

I would say using custom attributes is okey and valid as soon as many frameworks like Angular use it as well. Your can find some information about it here

Should you use it? Hard to say. For many situations cookies is much easier and cleaner option as @mtb say in comment.

About data attribute you mentioned in your question:

HTML5 is designed with extensibility in mind for data that should be associated with a particular element but need not have any defined meaning. data-* attributes allow us to store extra information on standard, semantic HTML elements without other hacks such as non-standard attributes, extra properties on DOM, or setUserData.

For more information about it check this link

Community
  • 1
  • 1
Andurit
  • 5,612
  • 14
  • 69
  • 121