Reputation: 1814
To find form element from the element which triggered event. I use following code. but it seems crazy to me.
Is there a better way doing this?
$("#xx").click(function(event) {
var testValue = $(this).parent().parent().parent().parent().parent().parent().parent().data("test");
});
thank you in advance.
Upvotes: 1
Views: 93
Reputation: 8552
$("#xx").click(function(event) {
$(this).parents('#YourId').attr("firstForm");
});
for reference see this link : http://api.jquery.com/parents/
Upvotes: 0
Reputation: 21742
If your HTML is valid then simply do
$("#firstForm")
ids are unique (assuming valid HTML)
Upvotes: 1
Reputation: 14747
Crazy is right. :D
$(this).closest('#firstForm')
should do this for you.
Upvotes: 4