0

I want when the label content is Laptop hidden-panel2 and hidden-panel3 to be hidden and only hidden-panel to be shown. when I create the record from within the application it is working fine but when the record is added from the database it is not. what am I doing wrong.

<label id="AssetType"> @Html.DisplayFor(model => model.AType </label>

Div to hide

<div id="hidden-panel">
     <label class="label">@Html.DisplayFor(model => model.LaptopProcess)</label>
</div>

<div id="hidden-panel2">
     <label class="label">@Html.DisplayFor(model => model.pcProcess)</label>
</div>

<div id="hidden-panel3">
     <label class="label">@Html.DisplayFor(model => model.phoneProcess)</label>
</div>

Script to hide Div

$(document).ready(function () {
$("#AssetType").ready(function () {
    if ($('#AssetType').text() == 'Laptop') {
        $('#hidden-panel').show();
        $('#hidden-panel2').hide();
        $('#hidden-panel3').hide()
    }
})
});
  • 1
    If you're trying to _hide_ a div if it contains specific text using `$('#hidden-panel').show();` is the opposite of what you want. You want `$('#hidden-panel').hide();`. – Andy Jul 04 '21 at 06:14
  • I have multiple div to hide according to the text – Mouffaq Dalloul Jul 04 '21 at 06:16
  • Incidentally, [IDs must be unique](https://stackoverflow.com/questions/9454645/does-id-have-to-be-unique-in-the-whole-page) in a DOM tree. Multiple hidden panels with the same ID will likely cause problems. – showdev Jul 04 '21 at 07:01
  • @showdev they are unique (hidden-panel, hidden-panel2, hidden-panel3) – Mouffaq Dalloul Jul 04 '21 at 07:34
  • @showdev I mean they are unique but still not working – Mouffaq Dalloul Jul 04 '21 at 07:41
  • I see, thanks. It might help to include a [working example](https://stackoverflow.com/help/minimal-reproducible-example) to help demonstrate the issue. – showdev Jul 04 '21 at 07:48
  • @showdev I have explained it in a more understandable way – Mouffaq Dalloul Jul 04 '21 at 09:31
  • To troubleshoot, what are things that might be different between the method that works and the one that doesn't? – showdev Jul 04 '21 at 19:50
  • @showdev the only thing that made this jquery script to work is when adding the record from the application it self but when adding the same data record from the database the same script does not work – Mouffaq Dalloul Jul 05 '21 at 04:44

0 Answers0