Jump to content

JQuery focusout()


shadowayex

Recommended Posts

I'm trying to add a focus out on an element that was added dynamically by JQuery.The element was added with this line:

$(this).html("<input type=\"text\" value=\"" + text + "\" />");

The above adds the element fine (or at least it looks like it does). Now, I try to do this:

$(this).children("input").focusout(function()	{		alert("foo");	});

And I get $(this).children("input").focusout is not a function. And this:

$(this).children("input").bind("focusout", function()	{		alert("win");	});

Doesn't give me an error, but ti doesn't work either. And to make sure I was getting the element right, I tried this:

alert($(this).children("input").val());

And that worked fine.I'm new to JQuery, and I can't seem to figure out what's wrong. Any ideas?

Link to comment
Share on other sites

If you aren't doing this already, I would always make sure any code I want executed be defined within the ready method of the document object. In jquery, this would be accomplished like so:

$(document).ready(){  //all code}

http://api.jquery.com/ready/This makes sure the entire DOM has been loaded before executing code, adding event handlers, defining functions, etc.

Link to comment
Share on other sites

If you aren't doing this already, I would always make sure any code I want executed be defined within the ready method of the document object. In jquery, this would be accomplished like so:
$(document).ready(){  //all code}

http://api.jquery.com/ready/This makes sure the entire DOM has been loaded before executing code, adding event handlers, defining functions, etc.

Yep that's being done.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...