troubleshooting Question

setAttribute problem in IE

Avatar of Savitrikvl
Savitrikvl asked on
5 Comments1 Solution505 ViewsLast Modified:

I am facing problems with setAttribute function in IE.  I understand from what I read on the net that IE doesn't support it and will never support it.  I would like to understand if there is a solution for what I want to do that works both in IE (at least version 7 onwards) and Firefox.

My requirement is:

I am dynamically generating fields by using Javascript.  I need to assign properties like classes, names, IDs, events dynamically to these.  I am currently using setAttribute to do this.

Below is a sample code where I am using an alternate solution by hiding and showing hyperlinks.  While I can afford to do it for this example, I cannot in many places in the rest of my code.

So, if I can get help on satisfying my requirement in the below code without the alternate solution I am currently using, it will help me fix the rest of my code.
this HTML
<a href="javascript:void(0)"  id="edit" onclick="companyEdit();" >Edit</a>

is calling the function defined here:

<script language="javascript">
function companyEdit()
       alert('edit company');
   document.getElementById('edit').setAttribute("onclick", "saveCompany('save company');");
function saveCompany(msg)

I want to change companyEdit() to  saveCompany()  dynamically using setAttribute.
Above example is not working IE only.

For this i have  one alternative solution  

   i have another hyperlink  like
   <a href="javascript:void(0)" style="display:none"  id="save" onclick="saveCompany('save company');" >save</a>
   when somebody cick on edit link i am changing display:none to display:block.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros