You need to sign in to do that
Don't have an account?
JQuery doesn't work on elements not rendered at load time
Hi,
If you have an element conditionally not rendered at load time, how can I attach a jQuery function to it? I have a button which is hidden at load time but renders once all fields have been filled out. I have attached a jQuery function to listen for the button click and perform an action, but it doesn't work. I removed the rendered attribute from the button and magically, the jQuery worked! So I know its not the code, its because the element isn't rendered and so presumably doesn't exist within the DOM when the page is loaded.
So my question - how can I get the function to work on a button which is not rendered at load time?
Thanks
All Answers
Or at what scenario you need to do this?
Ah, thanks sfdcfox, that helped. The live method is depreciated so the docs say to use .on instead. I tried
but that didnt work, however
does, presumably because the action is attached initially to the body tag and so will work with anything rendered at the time of the click.
To answer the first question, I'm attaching jQuery to a button purely to apply effects. I'm new to jQuery and I'm just trying to make the user experience a bit more pleasant.
Thanks for the replies!