0

I want to show a display:none element on a click of anchor tag using jQuery show() function.

But it's showing the div element for a moment and then vanished I used return false and preventDefault functions but it stops the redirection of anchor tag to a certain page.


How I can solve this?

  <div id="assetlist" style="display:none">
                    @{
                        Html.RenderPartial("~/Views/Asset/_Asset_List.cshtml");
                    }
                    <!-- /.sidebar-menu -->
                </div>

    <script>
    $(document).ready(function () {
    $(".asset_managment").click(function(){
        $("#assetlist").show();
    });

});
</script>

    <li class="nav-link" >
        <a href="@Url.Action("Index", "Asset")" class="asset_managment">
            <img class="img_position" src="@Url.Content("~/admin-lte/img/asset_managment_icon.png")" width="50" height="50" />    Asset Managment
        </a>
    </li>

enter image description here

  • Use `.hide()` instead of `.show()` [See the example here](https://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_eff_show_hide) – Sameer Mar 05 '20 at 05:03

2 Answers2

0

You can do like this

$(document).ready(function() {
    $(".asset_managment").on('click', function(e) {
        e.preventDefault();
        $("#assetlist").show();
    });
});
<div id="assetlist" style="display:none">
    Show me
</div>

<li class="nav-link" >
    <a href="anything" class="asset_managment">
        click me
    </a>
</li>

<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
Nisharg Shah
  • 16,638
  • 10
  • 62
  • 73
0

Could you just try:

 $(document).ready(function () {
    $(".asset_managment").click(function(){
        $("#assetlist").attr('style', 'display:block !important');
    });

});

this is just gonna overwrite the display property of your div's inline style. hope this helps

Muhammad Murad Haider
  • 1,357
  • 2
  • 18
  • 34