Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form action value difference 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 of attr() but here it returns incorrect value

like image 242
Anna K. Avatar asked Dec 25 '22 01:12

Anna K.


1 Answers

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.

like image 190
Arun P Johny Avatar answered Jan 03 '23 10:01

Arun P Johny