Here is a simple form:
<form action="hello">
</form>
If I use
var action = $('form').attr('action');
I get the correct value, "hello". But if I use
var action = $('form').prop('action');
I get
http://localhost/hello
What's up with that?
I read that I should use prop() instead of of attr() but here it returns incorrect value
When you say prop
, it will get the absolute path of the target resource but .attr()
will read the attribute value as it is.
Since you have used relative path in the action, prop
will use the path of the current page to construct the actual url to which the form will be submitted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With