MVC 4 – Using HTML5 “data-” attributes with Jquery

a developer's notes - a semi-technical web development BLOG

You can create data- HTML attributes with your controls using this technique.

Define a new HTML Attributes anonymous object with your Html helpers. Below, I create a text box with some additional properties I want to be able to access with jQuery. Using properties that start with “data_”, you will be able to access the property with jquery’s data() method. Note: using property names that start with “data-” will result in a compilation error.

This is the HTML that gets rendered

Here is what jquery’s data() method converts property names to. Interestingly, the underscores are removed and camel casing is applied to the name.

data-dash-watch

Here is another good article on the subject.
http://unmatchedstyle.com/news/html5-data-attributes-jquery.php

View original post

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: