Date () Add Jquery dynamically

0

I would like to know the following. I am using the date function of jquery. As the HTML code is dynamically created, I can not assign the date.

//Aqui  tem um each
$('#div').append('<span class="vor" data-tipo_m="'+v.cob_tipo_mapa+'">'+v.cob+'</span>');

I tried to get the last value of class .vor and add the date function. But it was not possible. Then I added manually, as in the example above:

$('.vor:last').data("tipo_m", v.cob);

My question is, this will work in any browser. For the date () of jquery, when I inspect element it does not appear. The way I did create the attribute and then get the value with date () from jquery.

    
asked by anonymous 01.05.2015 / 21:56

1 answer

2

The $('.vor:last').data("tipo_m", v.cob); command you used does not add values but retrieves them.

To add use something like: jquery.data($('.vor:last'), "tipo_m", v.cob); . Note that for the jquery.data(...) method to add elements it needs three parameters in its signature.

See the jquery API reference here .

There's no problem doing it the way you did. Using the date is just an alternative. Note that the current jquery does not support older browsers like IE 6 (I'm not sure about IE 7).

    
01.05.2015 / 22:32