views:

48

answers:

1

I want to turn this:

document.getElementById("associatedDisplayDiv").innerHTML += formatedResult;

... into jquery.

I've tried doing this:

$("#associatedDisplayDiv").html( $("#associatedDisplayDiv").html() + formatedResult );

But this is not right, apparently. What happens is that this new line of code remove the value of a input somewhere:

<input id="ctl00__mainContent__ERecordingsInputControl__moodsHidden" class="hiddenField" type="text" name="ctl00$_mainContent$_ERecordingsInputControl$_moodsHidden"/>\

This is really weird because this line is the only thing I have to change to see this bug appear. So... what am I doing wrong?

Thanks

+4  A: 

Yes, it is weird. Why don't you try append?

$("#associatedDisplayDiv").append( formatedResult );
Anwar Chandra
oh, this works! thanks! ... but what was wrong with my way of doing this?
marcgg
element.html() is similar to element.empty().append(). is your input element inside the div?
Anwar Chandra
No it's not, they are in two different places.
marcgg
From what I understand, empty().append() reset the value and event of any element inside div. It just like recreating them again. Your input element might be bound to an event handler which referenced to any element inside the div. So I don't have any idea what the problem is, how asp.net control works is like a blackbox to me. Glad it works :)
Anwar Chandra