I've been searching around to determine what this line of code in an application I'm working on does:
var encodedString = $('<div />').text(variableName).html();
I understand that:
- Everything to the right of the = sign is assigned to encodedString.
- The
('<div />')
is a selector, and the<div />
part of that a self-closing tag. - I know that .text(variableName) displays the variableName string in the selected text field, and that .html() returns the html contents of the element.
But put all together, what does the line do? The ('<div />')
and the .html() parts totally confuse the whole line for me. Could someone please give me some direction, ideas or explanation?
It seems like a syntax question so I think the rest of the code may be unnecessary, but please tell me if that isn't the case.
This is from an app that I have to edit to fit my needs, so I have to understand the existing code before I can change it.
Thank you for any direction you can provide.