The below code works fine in FF but IE throws error because the onclick function contains quote in it. How to make this work in IE?
I’m doing something like this
<a href="#" onclick="add('1','val1')" id="link1">Link1</a>
<a href="#" onclick="add('2','val2')" id="link2">Link2</a>
<script>
function add(id,val) {
//do something
$('#link'+id).attr('onClick',$('#link'+id).attr('onClick').replace("add","remove"));
}
function remove(id,val) {
//do something
$('#link'+id).attr('onClick',$('#link'+id).attr('onClick').replace("remove","add"));
}
</script>
Example: After link1 is clicked the link should be updated to below
<a href="#" onclick="remove('1','val1')" id="link1">Link1</a>
changed onclick to href and voila it works in IE too.