How to use jquery in nested collections?
Hi,
In the application, I have a one-to-many relationship between Employee and it's wife, daughter, and son. So to enable the user to add multiple wives, daughters or sons, views for Wife, Daughter, and son are created under an EditorTemplates folder. Then, as and when required these views are loaded using @Html.EditorFor(x => x.Wives) or @Html.EditorFor(x => x.Daughters) or @Html.EditorFor(x => x.Sons) as many as times needed.
Now, in these views, say for example, in Wife.cshtml there are certain controls that I want to show conditionally. To do that, if I insert a script shown below, the page stops getting loaded. On removing the scripts from the view, it works normally.
- <script type="text/javascript">
- $(document).ready(function () {
- //Uncheck the CheckBox initially
- $('#gender').removeAttr('checked');
- // Initially, Hide the SSN textbox when Web Form is loaded
- $('#Male').hide();
- $('#Female').hide;
- $('#gender').change(function () {
- if (this.checked) {
- $('#Male').show();
- $('#Female').hide();
- }
- else {
- $('#Female').show();
- $('#Male').hide();
- }
- });
- });
- </script>
Therefore, please tell me how to use jquery in the scenario described above.