4

I want to know is there any way to add a custom attribute to the a HTML element.

For example ,

<input type="text" name="txtNAME1" displayName="dname1" />

In the above example the custom attribute "displayName" is not a standard HTML attribute. So I want to know if I can define the same and push the intended value to the server and access the same attribute's value.

Thanks in advance!

Rashmi
  • 629
  • 1
  • 11
  • 35

1 Answers1

4

Which language are you using? You can do this in C# using

<input type="text" name="txtNAME1" displayName="dname1" runat="server" id="test" />

Then, in the code behind:

test.Attributes["displayName"];

You can also access it in jQuery with

$('test').attr('displayName')

and send it through to the server via a handler.

Chris Dixon
  • 9,147
  • 5
  • 36
  • 68
  • Thanks Thedixon, well i want to implement this in ruby. Will try this if it works as well.. :) – Rashmi Mar 21 '11 at 10:05