$ ("# myForm"). attr ("action") returns a form element instead of undefined for forms without any action

I have this basic example:

<!doctype HTML>
<html>
<head>
    <script src="jquery-1.4.2.min.js" type="text/javascript"></script>
    <script>
        $(document).ready(function(){
            $("#showAction").click(function(){
                alert($("#myForm").attr("action"));
            });
        });
    </script>
</head>
<body>
<form id="myForm">
    <input type="text" name="action" value="myAction" />
</form>
<input type="button" value="click me" id="showAction" />
</body>
</html>

When you click "click me", you can see the tag

$("#myForm").attr("action"); 

Actually does not return the attribute of the element. It returns a child of the form named "action".

Is this the expected behavior? Is this a bug in jQuery?

+3
source share
2 answers

"", Netscape - ( "", IMO), form.action , name <form>. , jQuery, JavaScript, ... jQuery .

, "action" "submit", form.submit().

+9

Source: https://habr.com/ru/post/1774560/


All Articles