1

I can't figure out what I'm doing wrong. I have dynamically generated input fields with class='freeze-date' that only works on the 1st datepicker input-field generated. I have the code @ http://jsfiddle.net/Someguy2k/L9nvs/3/

Thanks

1
  • As François Wahl said: the markup is invalid. You should always validate the markup as the first thing there are several services for that. being validator.w3.org my favorite. Commented Aug 16, 2012 at 5:48

1 Answer 1

2

There is several issues with your injected markup. All of you id attributes in each row of elements have the same value.
Not only is that invalid HTML but also results in side-effects such as this one.

jQuery will look for an id and stop when it finds the first match.
I fixed that particular issue with your calendar by adding the i value as an additional value to the id attribute.

...  id='freezeby" + i + "'  ...

See DEMO

If you find other elements are behaving the same when interacted with it is most likely due to the same reasons as I have seen the other id attributes also having the same issue.

Using Live()

In addition, you are using live(). Live has several issues and all the drawbacks are listed in the documentation. Memeory leaks, unexpected loss of events bindings, stopPropagation() doesn't work due to the way live() bubbles events and more.

Since jQuery 1.7 live() has been deprecated and on() is preferred. For your version it is preferred to use bind() for binding events to static elements and delegate() to bind events to dynamic elements.

Sign up to request clarification or add additional context in comments.

2 Comments

that worked and it's always the simple things that get me... what are the other issues with the injected markup? I'm not experienced with JQ - thank you for the help and critic.
You are welcome. Regarding the HTML, make sure you add some unique value to each element you generate in your loop, I used the i value as that is what you used in other places already. Regarding jQuery, the most important thing you will find is their online documentation. It is very clear and is always updated with latest news on deprecated functionality and so on. I linked all of the relevant documentation in the answer. Have fun :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.