Lets say I have a page with a div, which might or might not (no control over contents) have base64 encoded contents. I have a button, which when clicked will get the contents of the div, decode the base64 and then replace that same div with the decoded contents.
I know that innerHTML can get contents of whichever element.
I know that btoa() and atob() can decode base64, and there are enough functions on the web to do it for IE.
I however don’t know how to combine the two, and afterwards replace the contents of that same div with the decoded result. What would be the best way to do above thing? Jquery is available, other frameworks are not.
You could use the jquery
.html()method like thisand
Assuming that the div you want to target has a class
encodedapplied to it.. (that class is just an example for targeting the element)Demo at http://jsfiddle.net/gaby/k5SSH/1//