Here is the html: enter image description here

jquery:

$("docement").ready(function () { $(".close").on("click",function (e) { var el = $(this).parent().children(".kek"); console.log(el.val()); }); }) 

And even if I remove the hidden property, it still does not show the value

    2 answers 2

    The type="hidden" attribute (like the value property) does not make sense for the div element.

     var el = $(this).closest(".deserve").find(".kek"); console.log(el.text()); 

    or

     <input type="hidden" class="kek" value="3" /> 

    PS $("docement") -> $("document")

      The description of val clearly states that it is used to obtain the values ​​of form elements, such as input , select and textarea . When applied to other elements, an attempt will be made to get the value of the value property. The div element does not have this property.

      Instead, you can use the text or html method.


      If you really want to use val , you can add valHooks for div elements.

       jQuery.valHooks.div = { get: function(el) { return el.textContent; } }; var el = $('#d'); console.log(el.val()); 
       <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="d">div value</div>