Reputation: 100
I'm having more problem with jquery selector... I'm inserting user form sith POST ajax, and I might have more than one form with the same class at once.
I've manage to grab the last form inserted with this line :
var NewForm = $(".myform").last();
and it does the job ok as I cant use :
$(NewForm).css()...
To set the curent form display. Now I'm trying to have some "focusout" event to trigger. When I place the following code, the focusout event work, but for all ".myform" class.
$('.myform input[name="test"]').focusout(function() {
Alert('This Work');
});
I would need only the last form to have the focusout event attach. I've tried the following :
$(NewForm).children('input[name="test"]').focusout() {
Alert('this is not working');
});
without success, I've also replace "children".
the HTML is similar to this :
<div id="main">
<div class="myform">
<form class="formtype">
<input name="test">
</form>
</div>
</div>
Thank you for your input!
Upvotes: 1
Views: 118
Reputation: 50563
You can use this:
$('input[name="test"]', NewForm).focusout() {
Alert('this is not working');
});
That is, using the context parameter so you search for your selector only inside the NewForm
element.
Upvotes: 1