Delto
Delto

Reputation: 331

Adding mailto: link with jQuery

I need to .append a simple Website by John Bob in the footer of a website. However, I need the name John Bob to be a mailto: link. This has to be done with jQuery.

Here is what I have so far, but it's not working for me.

jQuery(document).ready(function($) {
    var e = "mailto:[email protected]";
  $("footer .copyright").append("<div> Website by <a href="" + $(e) + "" target='_top'>John Bob</a></div>");
});

Upvotes: 0

Views: 656

Answers (2)

Thangaraja
Thangaraja

Reputation: 956

Another interesting & clean approach is to use chaining.

$("<a target='_top'>")
  .text("John Bob")
  .attr("href", "mailto:[email protected]")
  .appendTo("<div>Website by </div>")
  .parent()
  .appendTo("footer .copyright")
  .end();

Demo: https://jsfiddle.net/6ptc3d8u/1/

Upvotes: 0

Tim Hysniu
Tim Hysniu

Reputation: 1540

jQuery(document).ready(function($) {
    var e = "mailto:[email protected]";
    $("footer .copyright").append('<div> Website by <a href="' + e + '" target="_top">John Bob</a></div>');
});

Pretty close.

Upvotes: 3

Related Questions