Reputation: 5897
I'm trying to write a simple jquery tab submit logic for a form that is isn't another rendered view
The code I am using is
$(function () {
$(".save").on("click", function () {
var href = $(this).closest(".contents").find(".ui-tabs-selected").attr("href");
debugger;
$(href).find("form").submit();
});
});
now when I click this my href variable is undefined, any reasons why? here is my HTML also
<section id="page-content">
<div class="contents">
<div class="workspace-column">
<div class="title">@Model.Name</div>
<div class="function-bar">
<a href="#" class="save">Save</a>
</div>
<div>
<div class="tab-set">
<ul>
<li><a href="@Url.Action("Information", "Update", new { id = Model.Id})">Update</a></li>
<li><a href="@Url.Action("Profile", "Update", new { id = Model.Id})">Profile</a></li>
</ul>
</div>
</div>
</div>
</div>
</section>
P.S. this is a cshtml file I am using with MVC.
Update ---
here is a picture of the generated HTML
Upvotes: 0
Views: 49
Reputation: 17366
You can give this a try:
You have to go deep through the DOM
as you're not considering <a>
tag which is having href
attribute like following
var href = $(this).closest(".contents").find(".tab-set")
.find('a').attr("href"); //.tab-set is just an example you can use ui-tabs-selected
Upvotes: 1
Reputation: 100
ui-tabs-selected will be on the li tags rather than the <a> tag won't it? So you need and extra jquery command to get the <a> e.g.:
var href = $(this)
.closest(".contents")
.find(".ui-tabs-selected a")
.attr("href");
I was also recommend using single quotes in your href for Information, Profile etc.
Upvotes: 1