Ie doesn’t execute these commands to html which is added/appended to the DOM.
It works for class names in the original document but anything appended it doesn’t seem to work while others do.
Any ideas to what i’m doing wrong guys…
Many thanks,
Dave
Since that function is getting assigned to all anchors (with a class of ‘remove’) currently available in the DOM it will not affect those which are added later.
There are a few ways round this:
You could simply re-assign this function to newly added anchors.
You could assign a function to the onclick event of a higher element in the DOM, for example you could assign the event to the document body and then find the target of the click using e.target||e.srcElement.
Or… you could use one of jQuery’s fancy plugins like liveQuery which monitors the DOM for changes and then re-assigns the event’s function when you add something. Although, be careful because liveQuery doesn’t really monitor the DOM; it just extends jQuery’s ‘append’,‘prepend’,‘html’,etc. methods and re-assigns when something is added, so if you add something to the DOM using another library or native JavaScript methods then liveQuery will not work.
When you add an event on to page elements, like the .click event, that applies only to the existing elements on the page. New elements added on to the page do not have that event added to them.
jQuery has a plugin called liveQuery so that you can tell jQuery that certain groups of elements are to be watched, so that an event can be added to elements that are added to the page via jQuery.
Well i’m simply trying to establish if either i’m doing something wrong or I am getting the correct result from ie and it doesn’t play friendly with what i’m trying to do. I’m all of a week into Javascript so there are many unanswered questions!
Your suspicions are correct. IE doesn’t play friendly. We still have to support IE because it has a large slice of the market, but boy oh boy there are many IE6 and IE7 issues that we wish we didn’t have to deal with.
At least we don’t have to deal with supporting IE5 problems much nowdays.
As a good example of browser support, Yahoo provides a graded support chart for different browsers and environments.
Either you’re using magical browsers or you’re assigning the event after elements have been added. Like Paul said, “When you add an event on to page elements, like the .click event, that applies only to the existing elements on the page.”
Have you got a link? How are the additional items being added to the DOM?
jQuery’s selector engine is second to none, in all common browsers, so I wouldn’t worry about the whole class/id/tag thing.
The additional items are getting added to the DOM via js.
jquery .load method in the case of external html pages.
js added DOM elements through ‘createElement’ and ‘appendChild’ to id.
When the elements get added and thus values changed I reload certain elements of the page.