data() does not look for an actual "data" attribute string value on
the DOM.

You have to set it with data(), like:
$("#myElement").data('name', 'foo-bar');

and get it with:
$("#myElement").data('name');

The second argument (value) is not limited to a string. You can use
objects, etc.

http://docs.jquery.com/Core/data

Additionally, "2009-08-2816C213" is not a valid class name. Class
names cannot begin with a number.


On Aug 18, 4:25 am, pixeline <aplennev...@gmail.com> wrote:
> Hi!
>
> i'm trying to store some additional information only useful for my
> javascript. I thought i could use a data html attribute to do that but
> it does not seem to work: console.log() returns "undefined"
>
> here is the relevant extract of  my code, in case i did something
> wrong:
>
>         <tr>
>                 <td><div class="event  2009-08-2816C213" 
> style="float:left;width:
> 65px" data="{eventLength: 6}">
>                                   <div class="event-title"><span
> class="classe">C213</span> - <span class="Prof">2TID1</span></div>
>
> </td>
>         </tr>
>
> javascript:  (document ready)
>
>  $('div.event').each(function(){
>         console.log('eventlength= '+$(this).data('eventLength'));
>     });
>
> that returns "undefined".

Reply via email to