0
Well, I’m banging my head on this code, I’m reading a book about jQuery, but I can’t make this code work, someone can give a hint on how to solve it, and what this method works for ($.fn.data).
$('#minhaLista li').each(function(){
var $li = $(this),
$div = $li.find('div.content');
$li.data('contentDiv', $div);
});
var $primeiroLi = $('minhaLista li:first');
$primeiroLi.data('contentDiv').html('new content');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="content">
<ul id="minhaLista">
<li>Primeiro item</li>
<li>Segundo item</li>
</ul>
</div>
"minhalista" is an ID, the correct would not be
var $primeiroLi = $('#minhaLista li:first');
?– Ricardo Pontual
well, so far so good, but what is the relation of $.fn.html() as a Setter in the code, "new content" should not have appeared in the list?
– user106463
After the last edit it seems that the script is working normally.
– Guilherme Nascimento
yes, I got it. Thank you!
– user106463
Put it as an answer and not in the question. I reversed the edition of the Question, now just you formulate an answer explaining in detail where it failed ;)
– Guilherme Nascimento
Related: jQuery does not use the HTML5 dataset on date?.
– bfavaretto