<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
title
>GFG TextEncoder encodeInto() method</
title
>
</
head
>
<
body
>
<
p
id
=
'javascript'
hidden>I Love javascript</
p
>
<
button
id
=
'btn'
>Click me to see results</
button
>
<
div
id
=
'result'
></
div
>
<
script
type
=
"text/javascript"
>
// Original string
const original = document.querySelector(
'#javascript').textContent
const btn = document.querySelector('#btn')
const result = document.querySelector('#result')
// Instance of TextEncoder
const encoder = new TextEncoder()
// Instance of TextDecoder
const decoder = new TextDecoder()
// encode() is just an another method
// defined in TextEncoder class
// It specifies the encoded result of strings
const encodedResult = encoder.encode(original)
// Decoding
const decodedResult = decoder.decode(encodedResult)
// Button listing for click event, when
// click occurs shows original string and
// Encoded and Decode values
btn.addEventListener('click', () => {
result.innerHTML = `
Original: ${original}
Encoded Value: ${encodedResult}
Decoded Value: ${decodedResult}`
})
</
script
>
</
body
>
</
html
>