If i use var ac...">

The difference in the values ​​of the action form in prop and attr

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 attr (), but here it returns the wrong value

+4
source share
1 answer

When you say prop, it will get the absolute path to the target resource, but it .attr()will read the attribute value as it is.

Since you used the relative path in action, you propwill use the path to the current page to create the actual URL to which the form will be submitted.

+7
source

All Articles