babyboomer Posted October 19, 2018 Share Posted October 19, 2018 I would like to call the jquery text() method with a string argument that includes the HTML character entity for the copyright symbol (©). I've tried numerous variations of the following theme: $('#copyright').text('© ' + date.getFullYear() + ' John Doe'); So far, nothing I've tried has produced the desired result. Specifically, the HTML "& copy;" entity is not getting translated into the copyright symbol. Is it possible to pass an HTML character entity in this way? Link to comment Share on other sites More sharing options...
dsonesuk Posted October 19, 2018 Share Posted October 19, 2018 .text() will render that as a textual representation and renders '<' and '>' as < and > so © will become &copy; use .html() instead. Link to comment Share on other sites More sharing options...
babyboomer Posted October 20, 2018 Author Share Posted October 20, 2018 6 hours ago, dsonesuk said: .text() will render that as a textual representation and renders '<' and '>' as < and > so © will become &copy; use .html() instead. Okay. I'm not sure I follow all of that, but the bottom line is that I did try the .html() method… var d = new Date(); $('#copyright').html('© ' + d.getFullYear() + ' John Doe'); … and it seems to be working! Thank you! Link to comment Share on other sites More sharing options...
dsonesuk Posted October 20, 2018 Share Posted October 20, 2018 Any html character codes (<, >, &) inserted into .text() is converted to html entity equivalent ('<', > &), if you use. var a = "Hello World! & Universe! ©"; $('#copyright').text('<span>' + a + '</span>'); You will actually see in the browser page <span>Hello World! & Universe! ©</span> because it is not html now, it shows as html entities textual character equivalents "<span>Hello World! & Universe! &copy; </span>". Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now