Nehemc Nehemc - 6 months ago 8
Javascript Question

Inserted div text to input field and need to know if div is empty?

$('#form input[id=Amount]').val(parseInt($('#eventamount').text()));

<div id="eventamount">0</div>

<div id="form">
<input type="text" name="Amount" id="Amount" class="cat_textbox" value="" readonly="true" />
</div>


Condition is if the div#eventamount is empty then hide the div#form or there is no div#eventamount exists then also hide the div#form?

Could you please help me to resolve this issue.

Answer
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
</head>

<body>
    <div id="eventamount">0</div>

    <div id="form">
        <input type="text" name="Amount" id="Amount" class="cat_textbox" value="" readonly="true" />
    </div>
    <script>
        $(function () {
            if ($("#eventamount").text() == null || $("#eventamount").text() == "")
            {
                $("#form").hide();
            }
        })
    </script>
</body>
</html>

you can try this