Welcome Guest, Not a member yet? Register   Sign In
Applying jQuery to Dynamically Created Elements
#7

[eluser]slowgary[/eluser]
Right, but he's not binding an event listener, he's just trying to .hide() something that's not there.

Fielder, when you call a method in jQuery, it looks for the element(s) matched against the selector and does it's work on them. If there aren't any matching elements, it doesn't sit around waiting for one to be born. If you are binding an event listener however, jQuery has the .live() method which actually does sit around watching for any new DOM elements so that it can bind the event listener. In your case, you don't really want an event listener bound, you just want to hide it... so the idea is to just bind an event listener to the 'load' event, which triggers as soon as the element gets injected into the DOM.

I still think that it's a bad way of doing things, you're using JS to handle something that CSS does perfectly. Also, there's a high likelihood that in many browsers you will see the '#store_body' element pop into existence then disappear, especially in a slow browser like IE. Using native CSS would be much faster and less complicated, and I can't think of any good reason you couldn't already have that specified in your CSS, I'm sure you just hadn't thought of it yet (and you haven't even had the chance to reply to these posts).


Messages In This Thread
Applying jQuery to Dynamically Created Elements - by El Forum - 06-21-2009, 09:33 PM
Applying jQuery to Dynamically Created Elements - by El Forum - 06-21-2009, 11:07 PM
Applying jQuery to Dynamically Created Elements - by El Forum - 06-21-2009, 11:19 PM
Applying jQuery to Dynamically Created Elements - by El Forum - 06-21-2009, 11:32 PM
Applying jQuery to Dynamically Created Elements - by El Forum - 06-22-2009, 07:05 AM
Applying jQuery to Dynamically Created Elements - by El Forum - 06-22-2009, 07:23 AM
Applying jQuery to Dynamically Created Elements - by El Forum - 06-22-2009, 07:45 AM
Applying jQuery to Dynamically Created Elements - by El Forum - 06-22-2009, 11:28 AM
Applying jQuery to Dynamically Created Elements - by El Forum - 06-22-2009, 12:28 PM
Applying jQuery to Dynamically Created Elements - by El Forum - 06-22-2009, 12:29 PM
Applying jQuery to Dynamically Created Elements - by El Forum - 06-22-2009, 04:13 PM
Applying jQuery to Dynamically Created Elements - by El Forum - 06-22-2009, 05:56 PM



Theme © iAndrew 2016 - Forum software by © MyBB