script.js 1017 B

12345678910111213141516171819202122
  1. // Manipulation d'attributs / propriétés
  2. var theChoice = $('#the-choice');
  3. var the2ndChoice = $('#the-2nd-choice');
  4. // Similaire
  5. console.log("theChoice.attr('id')", theChoice.attr('id')); // renvoie "the-choice"
  6. console.log("theChoice.prop('id')", theChoice.prop('id')); // renvoie "the-choice"
  7. // Différent
  8. console.log("theChoice.attr('checked')", theChoice.attr('checked')); // renvoie "checked"
  9. console.log("theChoice.prop('checked')", theChoice.prop('checked')); // renvoie true
  10. // Différent
  11. console.log("the2ndChoice.attr('checked')", the2ndChoice.attr('checked')); // renvoie undefined
  12. console.log("the2ndChoice.prop('checked')", the2ndChoice.prop('checked')); // renvoie false
  13. setTimeout(function() {
  14. var the3rdChoice = $('input[type="checkbox"]:eq(2)');
  15. the3rdChoice.attr('id', 'the-3rd-choice');
  16. the3rdChoice.prop('checked', true);
  17. the3rdChoice.after(' <label for="the-3rd-choice">J\'aime les pâtes</label>' );
  18. console.log("the3rdChoice.attr('id')", the3rdChoice.attr('id'));
  19. }, 3000);