This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I am trying to insert a content dynamically via innerHTML thing in DIV tag. The content is reflected as soon as I call BUT when I try to get that data back via method it doesn't give me the elements which I inserted. Here is the example code I have,
NOTE: I had to edit on click method name here to be onClick1 to avoid the HTML content error I was getting while doing the post Please change it to be right one if you want to test it.
Does anybody have some clue what is happening here?
The reason I want to do this functionality is -- I have some HTML content which I have to allow users load in my page just by putting it in textarea and my code should identify all that is loaded in it BUT I want to avoid "parsing" myself so I am piggybacking on HTML DOM itself by first inserting that HTML data specified in textarea to the hidden DIV tag and then doing parsing based on method.
Can somebody throw some light on this? Is there a workaround or other way to achieve what I want to do? Please let me know if I sound unclear.
div does not have a name attribute, so that might b the start of your troubles.
Have you looked into getElementsByTagName()
Joined: Nov 04, 2001
Thanks much for the guidelines. You are right, div doesn't have name attribute as such. Probably only form fields are supposed to have it.
The issue is I can't use ID attribute as that would add much complexity in my code for no reason.
Also, I noticed that getElementsByTagName doesn't work properly in Firefox. I got the div element array but I can't check the name attribute on it in Firefox. IE works fine in that case.
So here is how I am getting around the problem now,
This above code works for IE and firefox both. I don't know how long it would work though as still I end up using name attribute in case of IE (in the for loop where I prepare the array of elements) BUT for now it seems it should work. I don't know if this would work in IE7 too.