I have some code that works fine; it displays a button when a checkbox is checked. But now I want to change something and in that case there will be more checkboxes (they are generated by the content of a database so the number is not clear now).
But the solution is based on the ID of an element and having multiple the same ID's is not valid ánd it does not work.
I have the code here: https://codepen.io/anon/pen/jKOLew?editors=1111. As you can see only the first checkbox enables the div, the second doesn't.
Can somebody tell me how to solve this?
The code is this:
html:
<input type="checkbox" id="chkMessage" />Do you have Passport?<input type="checkbox" id="chkMessage" />Do you have Passport? <div id="dvMessage" style="display: none">Passport Number: <input type="text" /></div>`
And javascript:
`$(function() { $("#chkMessage").click(function() { if $(this).is(":checked")) { $("#dvMessage").show(); $("#AddMessage").hide(); } else { $("#dvMessage").hide(); $("#AddMessage").show(); } });});`
Aucun commentaire:
Enregistrer un commentaire