I'll try to make my question as simple and clear as possible. So i recently read the .prop()
vs .attr()
page on the stackoverflow, and decided i'd start using prop()
instead of attr()
.
HTML
<form action="php/select.php" method="POST" class="ajax">
<fieldset>
<legend>Show</legend>
<div>
<input type="submit" value="Show Servers"/>
</div>
<div id="output"></div>
</fieldset>
<input type="hidden" name="action" value="SHOW_SERVERS"/>
</form>
JQuery
$(document).ready(function(){
$("form.ajax").on("submit",function(e){
e.preventDefault();
var t=$(this);
var form=t.serialize();
var method=t.prop("method");
var url=t.prop("action");//Before: t.attr("action");
console.log(url);
});
});
Here comes the weird part, when i submit that form, what it prints in the console is this
My question is then:
Why does JQuery return an input element rather than the value of the form action property?
Why can .prop()
get the value of the method attribute, but not the action attribute
PS: I already know the input has the property name="action"
.