1

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.

1
  • your dec is empty string. Try this document.getElementById("display1").innerHTML = "abc";//dec; and you will see Commented Dec 2, 2015 at 7:04

2 Answers 2

2

That's because your script is executed before the div is added to DOM. Move your script below the div, best before </body> tag.

Sign up to request clarification or add additional context in comments.

1 Comment

You are welcome. Can you then check the answer as accepted?
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.