I'm a beginner in the world of javascript and jquery, and I've encountered an issue with a piece of code that swaps one text for another. The problem arises only during the initial click on the div.
Any suggestions? I suspect I might be calling it incorrectly, but I'm unsure about how to proceed.
Here's a fiddle for reference: http://jsfiddle.net/pauljackson/4r8v6/
JavaScript:
$(document).ready(function() {
$("#showemail").click(function() {
var $self = $(this);
if ($self.text() == "Contact")
$self.text("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="30435f5d5557454970445855595e4455425e55441e535f5d">[email protected]</a>");
else
$self.text("Contact");
});
});
HTML:
<div id="showemail">
Contact
</div>
CSS:
#showemail:hover {
cursor:pointer;
}
Appreciate any help!