Swap image on tab selected jQuery

  Kiến thức lập trình

How can I simplify this into one single function:

  $("#tab-one").click(function() {
    var imageUrl = "img/img-1.png";
    $(".masthead.product-detail").css("background-image", "url(" + imageUrl + ")");
  });
  $("#tab-two").click(function() {
    var imageUrl = "img/img-2.png";
    $(".masthead.product-detail").css("background-image", "url(" + imageUrl + ")");
  });
  $("#tab-three").click(function() {
    var imageUrl = "img/img-3.png";
    $(".masthead.product-detail").css("background-image", "url(" + imageUrl + ")");
  });

Many thanks in advance!

1

LEAVE A COMMENT