Create a mbox with at.js 2.x

Try closing your <div> tag before the script.

Description description

Environment
Adobe Target

Issue
The mboxCreate method doesn’t work with at.js 2.x.
How do you create a mbox div at the page level?

This code below was unsuccessful:

<div class="mboxDefault">

adobe.target.getOffer({

"mbox": "customTestMbox",

"params": {

"status": "true"

},

"success": function(offer) {

adobe.target.applyOffer( {

"mbox": "customTestMbox",

"offer": offer

} );

},

"error": function(status, error) {

console.log('Error', status, error);

}

});

</div>

Please compare this to the code in the Solution below.

Resolution resolution

Solution
Try closing your <div> tag before the script.

Example:

<div class="mboxDefault">
  default content to replace by offer
</div>
<script>
  var el = document.currentScript.previousElementSibling;
  adobe.target.getOffer({
    mbox: "mboxName",
    params: {
      param1: "value1",
      param2: "value2"
    },
    success: function(offer) {
      adobe.target.applyOffer({
        mbox: "mboxName",
        selector: el,
        offer: offer
      });
    },
    error: function(error) {
      console.error(error);
      el.style.visibility = "visible";
    }
  });
</script>
recommendation-more-help
3d58f420-19b5-47a0-a122-5c9dab55ec7f