0

On the click handler of a button I want to add a hidden element inside a div :

...
<div id="produits_choisis"></div>
...
<script>
$(document).ready(function(){
    $('#btnOne').click(function() { // btnOne is a HTML button
        $('#produits_choisis').append("<input type='hidden' id='produit_x' />");
    });
...
});

When I click the button then I look the page's source code , but the div produits_choisis is still empty ! So why is it empty ?

pheromix
  • 18,213
  • 29
  • 88
  • 158

1 Answers1

4

JavaScript operates on the in-memory DOM, not the original source code to the page.

Use a DOM inspector to see a representation of the modified DOM.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • 3
    "a DOM inspector", like right-click -> inspect element and the DOM inspector that shows up when you press F12. – GolezTrol Sep 28 '14 at 12:39
  • Ok I made right-click->inspect element , and I saw the hidden element in the source code ! thank you very much ! – pheromix Sep 28 '14 at 12:42