Reputation: 2228
I have a Javascript code for decryption, now i want to display the decryption string inside a div. I have tried using the following code.
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
<script>
var decrypted = CryptoJS.AES.decrypt("dsfsdffd", "dsfsdf");
var dec = decrypted.toString(CryptoJS.enc.Utf8);
document.getElementById("display1").innerHTML = dec;
</script>
<div id="display1"></div>
But the above code not working. What i have done wrong. Is there any solution.
Upvotes: 1
Views: 45
Reputation: 25527
Since you have tagged the question with jQuery, here is the jQuery solution
$(document).ready(function () {
var decrypted = CryptoJS.AES.decrypt("dsfsdffd", "dsfsdf");
var dec = decrypted.toString(CryptoJS.enc.Utf8);
$("#display1").html(dec);
});
Here you can place your script before the elements.
Upvotes: 1
Reputation: 5061
That's because your script is executed before the div is added to DOM.
Move your script below the div, best before </body>
tag.
Upvotes: 2